In JavaScript, arrays are also classes, so you can instantiate an array object with the following code
var Myarr = new Array ();
After instantiating, add an array element, such as the following code:
myarr[0]=1;myarr[1]= ' test '; myarr[' both ']=2;myarr[' three ']= "3333";
However, you can also create arrays and add array elements directly using the following code
var myarr=[1, ' Test ', 2, ' 3333 ']
It should be noted that the keys and values of the arrays in JavaScript can be strings, which is modeled by the object, which has already been said, the array is also the class (the class in JavaScript is very special), because Object.property is equivalent to the object[' property I've learned that PHP is used to this way, but when iterating through arrays, it's important to note that array subscripts are not numbers, especially for loops and while loops, while JavaScript has a foreach () {} loop similar to PHP. But JavaScript is for. In Loops, such as the following code
var myarr=new Array (); myarr[0]=1;myarr[1]= ' test '; myarr[']=2;myarr[' three ']= ' 3333 '; for (iter in Myarr) { document.write (iter+ ' ==> ' +myarr[iter]);}
In front of ITER is an iterator that automatically points to the next element each time.
The way in which traversal is traversed depends on the contents of the array, on the one hand, and on the individual preferences.
An array of javascript