const dontPickFrom = ['item3', 'item4'];
const data = {'item1': 1, 'item2': 2, 'item3': 3, 'item4': 4, 'item5': 5};
I have this above data and would like to get rid of the item3
and item4
without using delete
. So, the end product would be
{'item1': 1, 'item2': 2, 'item5': 5}
. I did it below but it's not outputting the result that i want.
removeSomeValues() {
return Object.keys(data).reduce((acc, key) => {
if (!dontPickFrom.includes(key)) {
return {...acc, [key]: data[key]};
}
}, {})
}