How do I create an array if it does not exist yet? In other words how to default a variable to an empty array?
If you are talking about a browser environment then all global variables are members of the window object. So to check:
if (window.somearray !== undefined) { somearray = []; }