I am working with an immutable object that I need to add subtract an array of values from.
I know it\'s possible using ES6 destructing with the following.
arrayToRemove.reduce((obj, key) => {
const { [key]: value, ...remainder } = obj
return remainder
}, originalObj)
You could use a computed property names with a dummy as target property.
Read more here: object property assignment pattern [YDKJS: ES6 & Beyond]
var originalObj = { foo: 1, bar: 2, baz: 3, },
arrayToRemove = ['foo', 'bar'],
result = arrayToRemove.reduce((total, key) => {
const { [key]: dummy, ...remainder } = total;
return remainder;
}, originalObj);
console.log(result);