conditionally add to object javascript code example
Example 1: js conditional object key
const object = {
...bool && { foo: 2 },
}
Example 2: conditionally add property to object ts
const a = {
...(someCondition && {b: 5})
}
const object = {
...bool && { foo: 2 },
}
const a = {
...(someCondition && {b: 5})
}