I have multiple properties that can be assigned to an Object depending on the same conditional
const condition = some boolean;
const foo = [
bar.fizz,
bar.fuzz,
bar.fat,
condition ? bar.arr[index].bat : '',
condition ? bar.arr[index].bot : '',
];
Is there any way I can conditionally assign those last two in the ternary (because they rely on the same conditional)?
I know of
...(conditional ? [
bar.arr[index].bat,
bar.arr[index].bot
]
: []),
But the only problem with that is that if the conditional is false...then those indices won't exist in the final object. I'll need them to default to empty strings.
I think
...(conditional ? [
bar.arr[index].bat,
bar.arr[index].bot
]
: ['', '']),
would work? Anyone see anything wrong with that or is there a better way?