Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to declare and initialize global arrays in javascript

In my html code, I need a global array which I use throughout my application. How to create and initialize global array variable in javascript..

like image 575
user25 Avatar asked Nov 29 '25 04:11

user25


1 Answers

You can do it several ways :
In the global scope :

var arr = [];

Binding the array to the global namespace:

window.arr = [];

or, for running the code in other environments, where the global object is not necessarily called window:

(function(global){
    global.arr = [];
})(this);
like image 130
gion_13 Avatar answered Dec 01 '25 18:12

gion_13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!