JS Array Array Detailed _ Basics

Source: Internet
Author: User
1. Method of declaring array
(1): Arrayobj = new Array (); Creates an array.
Copy Code code as follows:

var arr1 = new Array ();

(2): Arrayobj = new Array ([size]) creates an array and specifies the length, not the upper limit, but the length.
Copy Code code as follows:

var a = new Array (5);

(3): Arrayobj = new Array ([element0[, element1[, ...) [, ELEMENTN]]] Creates an array and assigns a value.
Copy Code code as follows:

var a = new Array (["B", 2, "a", 4,]);

(4): Arrayobj = [Element0, Element1, ..., ELEMENTN] Create an array and assign a value shorthand, note that the brackets here do not indicate that it can be omitted.
Copy Code code as follows:

var a = ["B", 2, "a", 4,];

(note): Note the difference between "[]" and "[]"
Copy Code code as follows:

var a = new Array (5); To create an array of length 5
var a = new Array ([5]); It means to create an array with a length of 1, and the first digit is 5.

2. Common methods of arrays
3. The operation of the array (send address)
Copy Code code as follows:

var t2=new Array ();
T2[0]=1;
t2[1]=2;
Test2 (T2); Send address (array)

function Test2 (var2) {
for (Var i=0;i<var2.length;i++) {
var2[i]=var2[i]+1;
}
}
for (Var i=0;i<t2.length;i++) {
Alert (T2[i]);
}

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.