js conditional key code example
Example 1: js conditional key
const object = {
...bool && { foo: 2 },
}
Example 2: conditionally add key to object javascript
const condition = getCondition();
const additionalCondition = getAdditionalCondition();
const person = {
firstName: "Max",
...(condition && { lastName: "" }),
...(additionalCondition && { addition: "" }),
};