If it was as part of a code block, I could do this:
const obj = {a: 1, b: 2};
delete obj.a;
console.log(obj);
Or this:
const {a, ...rest} = {a: 1, b: 2};
console.log(rest);
Is there a way to do this in an expression? Like this (pseudocode!):
console.log(Object.removeProperty({a: 1, b: 2}, 'a'));
Context / use case
I am aware of How do I remove a property from a JavaScript object? but the answers always seem to use statements, not expressions.
I want expressions as I'm in a middle of mapping one object to another, like this:
function mapSomethingToSomethingElse(obj) {
return {
prop1: obj.prop1,
prop2: obj.prop2,
prop3: {
...Object.removeProperty(obj.prop3, 'a') // <- HERE
abc: def,
},
// ...
}
}
I can hide the statements into a helper function, that's always an option, but in my specific case, I'd be happy enough with in-line expression if one can be written in JavaScript.