how can i define conditional array elements? i want to do something like this:
const cond = true; const myArr = [\"foo\", cond && \"bar\"]; >
const cond = true; const myArr = [\"foo\", cond && \"bar\"];
if you are using es6, I would suggest
let array = [ "bike", "car", name === "van" ? "van" : null, "bus", "truck", ].filter(Boolean);
This array will only contain value "van" if name equals "van", otherwise it will be discarded.