1. What is an array?
An array object uses a separate variable name to store a series of values. That is, the array can store all values with a variable name, each of which has its own ID, so it is easy to access any value with the variable name.
2. Creating an array
(1) General method:
var mycars=new Array ();
Myarr[0]= "Volvo";
Myarr[1]= "BMW";
Myarr[3]= "Saab";
(2) Concise way:
var mycars=new Array ("Volvo", "BMW", "Saab");
(3) Literally:
var mycars=["Volvo", "BMW", "Saab"];
3. Accessing an array
Access to an element by specifying the array name and index number;
The representation of an array is a contiguous memory address in memory
The array name is actually the first address of the contiguous memory address
4. Properties of the array
(1) Duration: length
Syntax: mycars.length;
Note: Since the index of an array always starts with 0, the upper and lower bounds of an array are: 0 and length-1, respectively. The length of an array is 5, and the upper and lower bounds of the arrays are 0 and 4, respectively. At the same time, the length property of the JavaScript array is variable, which requires special attention.
Two or two-D arrays
1. Statement 1
1 var myarr=new Array ();2for (Var i=0;i<3; i++) {3 Myarr[i]=newArray ();4 For (Var j=0;j<6;j++) {5 Myarr[i][j]= (i) * (j);6 document.write (myarr[i][j]+ ' ');7 }8 document.write (' <br/>');9}
Statement 2
1 var myarr=[[1,2,3],[4,5,6]];
JS's Array