We can conditionally insert elements in an Array, there's one way to do that:
const flag1 = true
const flag2 = false
const arr = [
element1,
element2,
...(flag1 ? ['element'] : []),
]
flag1
values will be present in this Arrat, while flag2
not.
I also wrote an article regards objects.