Is there a nicer way (for example with filter
) to remove values from object than this?
const filters = {
a: null,
b: 0,
c: 'xxx',
d: 'abc',
}
const MY_FALSY = [undefined, '', null];
const newFilters = Object.entries(filters).reduce(
(a, [k, v]) =>
MY_FALSY.indexOf(v) > -1 ? a : { ...a, [k]: v },
{}
);
Is there a better way to do it? I tried to use filter but I had to use delete
which as I know we should avoid.
NOTE: I don't want to use any libraries like underscore.js
Outcome:
{
b: 0,
c: 'xxx',
d: 'abc',
}