How can I use an array defined in one JavaScript file in another JavaScript file?

100 Views Asked by At

I have written the following code:

var json = result;
AJS.log("JSON Data Print")
AJS.log(json)

var treeData = [];
json_arr.push(json);
/*for(var x in json){
    json_arr.push(json[x]);
}*/
AJS.log("Copying JSON Data in to an array")
AJS.log(treeData)

Now I want treeData to be available in a different JS file. How can it be done?

1

There are 1 best solutions below

5
On

You can use window object so that it will be available globally. It will attach it as the property of global.

window.treeData = treeData