Proposal: deleting properties in object initializer expression

# Douglas Meyer (4 months ago)

With spread properties, it would be great to be able to remove specific properties:

const obj1 = { one: 1, two: 2, three: 3 };
const obj2 = {
...obj1,
delete three // <-- new syntax
};

obj2 would be { one: 1, two: 2 }. This syntax is visually similar to the getter/setter syntax. This should also support the computed property approach:

const propName="three";
const obj1 = { one: 1, two: 2, [propName]: 3 };
const obj2 = { ...obj1, delete [propName] };

There are 2 ways of currently doing this:

const { three, ...obj2 } = obj1; // has the side-effect of creating
unnecessary variable `three`.
delete obj2.three; // seems odd to create an object to then reach-in and
remove things.

It is worth noting that const obj2 = { ...obj1, three: undefined } is not the same thing, as obj2.hasOwnProperty('three') would still return true.