The array class can be defined as follows:
var avalues = new Array ();
If you know the length of an array in advance, you can pass the length with parameters
var avalues = new Array (20);
------------------The following 2 definitions are 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 arrays are defined in such a way that the output is the same, and a comma separator is found in the middle.
Alert (acolors.tostring ()); Output "Red,green,blue";
(2) string converted to array
We found that the array was converted to a string, with 1 more delimiters between the arrays ', ', and that string was converted to array arrays and must have delimiters. Can be a comma, or it can be another separator.
var scolors = "Red,green,blue";
var acolors = Scolors.split (', '); The string is converted to an array.
The above analysis of JavaScript array and string conversion (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.