I have been stuck on this awhile. Found a lot of example on how to remove based on key, but not on value.
I am trying to remove all keys that have value false.
Any help would be appreciated, It seems Object.keys only accesses keys, val seems to have no effect.
const names = {
1: false,
2: true,
3: true,
5: false
}
const newNames = Object.keys(names).reduce((object, key, val) => {
console.info('propName', key);
if (object[val] == true) {
object[key] = names[key];
}
return object;
}, {});
console.info('test', newNames);
// expected output I want should be {2:true, 3:true}
Any help would be appreciated.