Array declaration methods and other definitions 1. array declaration Methods
(1): arrayObj = new Array (); // create an Array.
The Code is as follows:
Var arr1 = new Array ();
(2): arrayObj = new Array ([size]) Create an Array and specify the length. Note that the length is not the upper limit.
The Code is as follows:
Var a = new Array (5 );
(3): arrayObj = new Array ([element0 [, element1 [,... [, elementN]) to create an Array and assign values.
The Code is as follows:
Var a = new Array (["B", 2, "a", 4,]);
(4): arrayObj = [element0, element1,..., elementN] creates an array and assigns a value in short. Note that brackets do not indicate that they can be omitted.
The Code is as follows:
Var a = ["B", 2, "a", 4,];
(Note): note the difference between "[]" and "[]".
The Code is as follows:
Var a = new Array (5); // creates an Array of 5 characters.
Var a = new Array ([5]); // creates an Array with a length of 1 and a first value of 5.
2. Common Methods of Arrays
3. Array Operation (Transfer address)
The Code is as follows:
Var t2 = new Array ();
T2 [0] = 1;
T2 [1] = 2;
Test2 (t2); // address (array)
Function test2 (var2 ){
For (var I = 0; I Var2 [I] = var2 [I] + 1;
}
}
For (var I = 0; I Alert (t2 [I]);
}