The array class can be defined as follows:
var avalues = new Array ();
If you know the length of the array beforehand, you can pass the length with the parameter
var avalues = new Array (20);
------------------the following 2 ways to define the same--------1-----------
var acolors = new Array ();
Acolors[0] = "red";
ACOLORS[1] = "green";
ACOLORS[2] = "Blue";
Alert (acolors[0]); Output "Red"
-------------------------------------------------2-----------
var acolors = new Array ("Red", "green", "blue"); and array definition arrays are equivalent.
Alert (acolors[0]); Output "Red" too
--------------------------
(1) Array converted to string
The above 2 kinds of array definitions, the output is the same, found in the middle there is a comma separator.
Alert (acolors.tostring ()); Output "Red,green,blue";
(2) string converted to array
We found that the array was converted to a string, there were 1 more delimiters ', ' between the arrays, and then the string was converted to array arrays, which had to be delimited. It can be a comma, or it can be a separate delimiter.
var scolors = "Red,green,blue";
var acolors = Scolors.split (', '); The string is converted into an array of arrays.
The cross-conversion of Javascript array and string.