How to create an array if an array does not exist yet?

前端 未结 7 1467
南旧
南旧 2020-12-07 21:43

How do I create an array if it does not exist yet? In other words how to default a variable to an empty array?

相关标签:
7条回答
  • 2020-12-07 22:40

    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 = [];
    }
    
    0 讨论(0)
提交回复
热议问题