It is sometimes necessary to manipulate arrays when writing webclinet-side scripts, and the syntax for declaring arrays in JavaScript is
Dim variable = new Array ();
It should be noted that there is no two-dimensional array concept in JavaScript, only one-dimensional.
Cases:
One-dimensional array generation, assignment, display method
function GetArray ()
{
var arr = new Array ();
Arr[0] = "0";
ARR[1] = "1";
for (i=0;i<arr.length;i++)
{
Alert (Arr[i]);
}
}
Two-dimensional array generation, assignment, display method (this method error)
function Get2darray ()
{
Alert (' Such declaration, assignment, display of two-dimensional array method is illegal ');
var arr = new Array ();
int[][] arr = new Array (); This writing is not true at all, and does not conform to JavaScript syntax, which can cause JavaScript scripts throughout the page to not execute
Arr[0][0] = 1;
ARR[0][1] = 2;
Arr[1][0] = 3;
ARR[1][1] = 4;
for (i=0; i<arr.length;i++)
{
for (j=0; j<arr[i].length;j++)
{
Alert (Arr[i][j]);
}
}
}
This is a common way of declaring arrays (in other languages, especially those that are commented out), but it turns out that this is illegal, further explaining that there is no definition of two-dimensional arrays in JavaScript.
Think of an old saying "only unexpectedly, not to do, there are solutions."
A workaround that copies each element of a one-dimensional array, and its value is also a one-dimensional array.
Two-dimensional array generation, assignment, display method (workaround)
function Get2darray2 ()
{
var arr = new Array ();
Arr[0] = new Array ();
ARR[1] = new Array ();
Arr[0][0] = "00";
arr[0][1]= "01";
arr[1][0]= "10";
arr[1][1]= "11";
for (i=0; i<arr.length;i++)
{
for (j=0; j<arr[i].length;j++)
{
Alert (Arr[i][j]);
}
}
}