No idea how to word this but say I'm trying to make an array of strings, and the existence of each string is dependant on a condition
What I'm doing right now is going
somelist = [
true ? 'foo' : null,
false ? 'bar' : null
]
Because I don't want to give any value to false conditions, but the only way I could figure out to do that was by giving them all null values.
I know that I could do an if statement for each and push it if so, but maybe there's a better way?
I just figured a kind of solution.
somelist = somelist.filter(value => value !== null)
but is there an even shorter way?