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