Something that has the same effect as:
const obj = {a:'a', b:'b', c:'c'};
const {a, b} = obj;
const result = {a, b};
Or, in ES5:
const obj = {a:'a', b:'b', c:'c'};
const result = Object.keys(obj)
.filter((key) => ['a', 'b', 'c'].includes(key))
.reduce((acc, key) => acc[key] = obj[key], {})
I thought
const result = { a, b } = obj;
would work, but apparently, it just has the same effect of:
const result = obj;
in that result
has all of the properties of obj and it also seems to 'point' to it (result.a = 'changed'
results in obj.a === changed
to be true). It this a bug?