How can I define conditional array elements?
I want to do something like this:

const cond = true;
const myArr = ["foo", cond && "bar"];

This works as expected and results in ["foo", "bar"] but if I set cond to false, I get the following result: ["foo", false]

How can I define an array with a conditional element?

11 Answers
11

Leave a Reply

Your email address will not be published. Required fields are marked *