via this stackoverflow, you can use the spread operator and the ternary operator to conditionally include or exclude something in an array declaration ala:
const myArray = [
'always this thing',
...(testFuntion() ? ['sometimes this thing'] : []),
'and always this thing',
];
No comments:
Post a Comment