I have a 2nd level array, that at a cetain point in the code can be ether undefined or contain value. If it is undefined I need to define it, without giving it any value.
this is what i did:
arr[arr2["stripID"]] = typeof(arr[arr2["stripID"]]) === 'undefined' ? [] : arr[arr2["stripID"]];
is there a better or shorter way?
Should do what you want.
The
||operator returns the first truthy value in the expression. Because an array is truthy, and the only other value it can be is undefined (falsy), this’ll work fine.