The Array class can be defined as follows:
var aValues = new Array();
If you know the length of the array in advance, you can pass the length with parameters
var aValues = new Array(20);
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var aColors = new Array();aColors[0] = "red";aColors[1] = "green";aColors[2] = "blue";alert(aColors[0]); // output "red"
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var aColors = new Array("red","green","blue"); // is equivalent to Array definition array.
alert(aColors[0]); // output "red" too
------------------------------------
(1) Array to string
The output of the above two array definition methods is the same, and I found that there is a comma separator in the middle.
alert(aColors.toString()); // output "red,green,blue";
(2) Convert string to Array
We found that Array is converted into a string, and there is an extra separator between the arrays ',' , so string is converted into an Array array, and there must be a separator. It can be a comma or other separator.
var sColors = "red,green,blue";
var aColors = sColors.split(','); // The string is converted into an Array array.
The above brief analysis of the conversion of JavaScript Array and string (recommended) is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.