Consider the following example:
const initObject = { a: 2, b: 3, c: 4 };
let shouldChangeB = false;
const newB = 4
const newObject = {
...initObject,
//shouldChangeB && b: newB - syntax error
//b: shouldChangeB ? newB : undefined - sets b to undefined
};
const newObject = shouldChangeB ? {
...initObject, b: newB
} : initObject;
//would work, but dirty if there's may keys we want to change by conditional
Is there a smart way to solve this problem?