How do I create an array if it does not exist yet? In other words how to default a variable to an empty array?
const list = Array.isArray(x) ? x : [x];
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
Or if x
could be an array and you want to make sure it is one:
const list = [].concat(x);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat