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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…