uncategorized

web-dev-js-useful-snippets

How to define an array with conditional elements?

1
2
3
4
5
6
7
8
// result in console ['foo', 'bar']
const items = [
'foo',
... true ? ['bar'] : [],
... false ? ['falsy'] : [],
]

console.log(items)
Share