how can i define conditional array elements? i want to do something like this:
const cond = true;
const myArr = [\"foo\", cond && \"bar\"];
>
There's a few different ways, but the way you're doing it won't really work for Javascript.
The easiest solution would be to just have an if statement.
if (myCond) arr.push(element);
There's also filter, but I don't think that's what you want here at all, since you seem to be going for "Add this one thing, if this one condition is true" rather than checking everything against some condition. Although, if you want to get really freaky, you can do this (would not recommend, but it's cool that you can).
var arr = ["a", cond && "bar"];
arr.filter( e => e)
Basically it will just filter out all the non true values.