The definition of an array:
Method 1.
Copy Code code as follows:
var mycars=new Array ()
mycars[0]= "Sharejs.com"
mycars[1]= "Volvo"
mycars[2]= "BMW"
Method 2.
Define and initialize together:
Copy Code code as follows:
var mycars=new Array ("Saab", "Volvo", "BMW");
Or:
Copy Code code as follows:
var mycars=["Saab", "Volvo", "BMW"];
JavaScript two-dimensional array, with one-dimensional arrays to simulate:
Method 1.
Copy Code code as follows:
var arr = new Array ([' A ', ' B ', ' C '],[' d ', ' e ', ' f ']);
ARR[0] Returns the first one-dimensional array, arr[0][0] returns the first element ' a ' of the first one-dimensional array, the same below.
Method 2.
Copy Code code as follows:
Arr=new Array ();
for (i=0;i<100;i++) {
Arr[i]=new Array (...);
}
Method 3.
Copy Code code as follows:
var arr=new Array (
New Array (),
New Array (),
New Array ()
);
The JavaScript array does not need to be set in length, it expands itself, and the array name. Length returns the number of elements
JavaScript arrays commonly used functions:
ToString (): Converts an array to a string
toLocaleString (): Converts an array to a string
Join (): Converts an array into a symbolic concatenated string
Shift (): Moves an element of an array's head out
Unshift (): Inserts an element in the header of an array
Pop (): Deletes an element from the tail of an array
Push (): Adds an element to the tail of the array
Concat (): Adding elements to an array
Slice (): Returns the part of an array
Reverse (): Sort the array in reverse order
Sort (): Sorting operations on array
Splice (): Inserts, deletes, or replaces an array element