In a React application I have this conditional add to an array,
var flag = .. // returns TRUE or FALSE
infographicObjectsArray.push({
"buttons": [
{"id":"viewAgreementsButton","variant":"outline-" + variantType,"text":"View Agreement","url":"/viewAgreementForm?id=" + eligibleSingleAgreement.id},
flag &&
{"id":"newAgreementButton","variant":variantType,"text":"New Agreement","url":"/newAgreementType"}
]
});
The 2nd item is false
rather than the object created. Note that this is React, so something else may be at play.