Suppose I have:
const apple = true
const pear = false
const coconut = true
I would like to have:
const activeFruits = ['apple', 'coconut']
How can I do something like this? This is what I've tried:
const activeFruits = [
apple ? 'apple' : '',
pear ? 'pear' : '',
coconut ? 'coconut' : '',
]
Then I have to filter out the empty string.
It works but doesn't seem to be to me the smartest way. Is there a better way?