How to define Global Arrays?

New is not a keyword.


var data = new Array();

Or, more succinctly:

var data = [];

After your edit you mention that the first script block is loaded asynchronously. Your code will not work as written. data is a global variable, once it is loaded onto the page. You need to use a callback pattern to properly execute the code.

Since you haven’t posted the asynchronous code I am not going to provide a callback sample. Though, a quick solution follows:

var interval = setInterval(function(){
    if(data) {
        /* ... use data ... */
}, 500);

Leave a Comment