varA=NewArray (NewArray (),NewArray (' B ', ' C '));d ocument.write (a[1][1]); To be blunt, we use a For loop to define a two-dimensional array! <script language= "javascript" type= "Text/javascript" >functionarray_2 (nrow,ncolumn) {vararray1=NewArray ();//defining a one-dimensional array for(i=0;i<nrow;i++){ //define each child element as an arrayarray1[i]=NewArray ();//---------------------------------------- for(n=0;n<ncolumn;n++) {Array1[i][n]= ";//at this point Aa[i][n] can be seen as a level two array }//--------------------------------------}returnarray1; } varArray_2= array_2 (3,2); array_2[0][1] = 1; array_2[0][2] = 2; array_2[1][1] = 3; array_2[[4]; document.write (array_2[The]);</script>//The dashed part can also be implemented using the push () method of the JS array built-in object, since 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 by the following statement: Array1[i].push (New Array (Ncolumn)); today also found that can also be defined as a two-dimensional array can also be made;varA=NewArray (NewArray (),NewArray (' B ', ' C '));d ocument.write (a[1][1]);p s: 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 parameters is an array, it is added as a single element to the array. If you want to combine elements from two or more arrays, use the Concat method. The Concat method returns an Array object that contains the connection for 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, then 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.
JavaScript two-dimensional array