conditionally add element to array javascript code example
Example: js conditional array element
const cond = false;
const arr = [
...(cond ? ['a'] : []),
'b',
];
// ['b']
const cond = false;
const arr = [
...(cond ? ['a'] : []),
'b',
];
// ['b']