JS processing methods that cannot define two-dimensional arrays themselves

Source: Internet
Author: User
var a= new Array( new Array(1,2), new Array( 'b' , 'c' )); document.write(a[1][1]);

To put it bluntly, we use the for loop to define a two-dimensional array!

?
<script language="javascript" type="text/javascript">    function Array_2(nRow,nColumn){        var array1=new Array(); // Define 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 time, AA [I] [N] can be considered as a list-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 line can also be implemented using the push () method of the JS array built-in object, because when arr1.push (arr2, the entire array arr2 is added to the arr1 array as an element. Therefore, the for loop in the dotted line can be replaced with the following statement: array1 [I]. push (new array (ncolumn ));

Today, we also found that the definition can also be made into a two-dimensional array;

 

VaR A = new array (1, 2), new array ('B', 'C '));
Document. Write (A [1] [1]);

PS: note the difference between push and Concat!

PushThe method adds new elements in the order they appear. If one of the parameters is an array, the array will be added to the array as a single element. To merge two or more elements in an array, useConcatMethod.

ConcatMethod returnsArrayObject, includingArray1And any other projects provided. Project to be added (Item1... Itemn) Is added to the array from left to right. If an item is an array, add its contentArray1. If the project is not an array, add it as a single array element to the end of the array.

Good !!!

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.