I am trying to achieve something similar in JavaScript with a one-liner. Can this be done without using an if statement?
// These versions add false to the array if condition = false
let arr = await getArray(params).push(condition && itemToAdd);
arr = await getArray(params).push((() => condition && itemToAdd)());
// This version adds undefined to the array if condition = false
arr = await getArray(params).push((() => { if (condition) return itemToAdd })());
(I included the getArray part because that's how it appears in my code and the array is not saved as a variable arr
. It is immediately returned to its calling function, hence the aim to avoid adding an extra line for the if statement...)