JavaScript two-dimensional array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.