I think this is a relatively simple thing I'm trying to do, but unsure how to accomplish it. Essentially I have an array to which I want to push a value (parent) ONLY if that value exists. I'm trying to accomplish it like so, but this doesn't compile. I want to only set the parent index if there is a value to it, I don't want parent: null
I'm trying to get a cleaner solution and not two pushes dependant upon the value being set. I would prefer the one push to encapsulate the check if possible
array.push({
id: id,
name: name,
parent ? parent: parent : null
})