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 want to check whether an array x exists and create it if it doesn't, you can do
x = ( typeof x != 'undefined' && x instanceof Array ) ? x : []
1.4m articles
1.4m replys
5 comments
57.0k users