insert condition in a object javascript code example
Example 1: insert condition in a object javascript
const a = {
...(someCondition? {b: 5}: {} )
}
Example 2: insert condition in a object javascript
const arr = [
...(isConditionTrue() ? [{
key: 'value'
}] : [])
];
const obj = {
...(isConditionTrue() ? {key: 'value'} : {})
};
Example 3: insert condition in a object javascript
const a = {
...(someCondition && {b: 5})
}