Conditionally add a key to a JS Object or Array

Conditionally add a key to an object: Conditionally add a key to an array: