Copy Code code as follows:
var a= new Array (new array (1,2), new array (' B ', ' C '));
document.write (a[1][1]);
To be blunt, use a For loop to define a two-dimensional array!
?
<script language= "javascript" type= "Text/javascript" >
function Array_2 (nrow,ncolumn) {
var array1=new Array (); Defining a one-dimensional array
for (i=0;i<nrow;i++) {
Define each child element as an array
Array1[i]=new Array ();
//----------------------------------------
for (n=0;n<ncolumn;n++) {
Array1[i][n] = '; At this point aa[i][n] can be thought of as a two-level array
}
//--------------------------------------
}
return array1;
}
var array_2= array_2 (3,2);
ARRAY_2[0][1] = 1;
ARRAY_2[0][2] = 2;
ARRAY_2[1][1] = 3;
ARRAY_2[1][2] = 4;
document.write (array_2[1][2]);
</script>
The dotted section can also be implemented using the push () method of the JS array built-in object, because Arr1.push (ARR2) will add the entire array arr2 as an element to the ARR1 array, so the for loop in the dashed line can be replaced with the following statement: Array1[i].push (New Array (Ncolumn));
It is also found today that the definition can also be made into two-dimensional arrays;
Copy Code code as follows:
var a= new Array (new array (1,2), new array (' B ', ' C '));
document.write (a[1][1]);
PS: Note the difference between push and concat!
The push method adds these elements in the order in which the new elements appear. if one of the arguments is an array, the array is added as a single element to the arrays. If you want to merge elements from two or more arrays, use the Concat method.
The concat method returns an Array object that contains a connection to the array1 and any other items provided. Items to add (item1 ... itemn) are added to the array in Left-to-right order. If an item is an array, add its contents to the end of the array1. If the item is not an array, it is added to the end of the array as a single array element.
Very good!!!