JS's Array

Source: Internet
Author: User
Tags javascript array

1. What is an array?

An array object uses a separate variable name to store a series of values. That is, the array can store all values with a variable name, each of which has its own ID, so it is easy to access any value with the variable name.

2. Creating an array

(1) General method:

var mycars=new Array ();
Myarr[0]= "Volvo";
Myarr[1]= "BMW";
Myarr[3]= "Saab";

(2) Concise way:

var mycars=new Array ("Volvo", "BMW", "Saab");

(3) Literally:

var mycars=["Volvo", "BMW", "Saab"];

3. Accessing an array

Access to an element by specifying the array name and index number;

The representation of an array is a contiguous memory address in memory

The array name is actually the first address of the contiguous memory address

4. Properties of the array

(1) Duration: length

Syntax: mycars.length;

Note: Since the index of an array always starts with 0, the upper and lower bounds of an array are: 0 and length-1, respectively. The length of an array is 5, and the upper and lower bounds of the arrays are 0 and 4, respectively. At the same time, the length property of the JavaScript array is variable, which requires special attention.

Two or two-D arrays

1. Statement 1

1 var myarr=new Array ();2for (Var i=0;i<3; i++) {3 Myarr[i]=newArray ();4 For (Var j=0;j<6;j++) {5                 Myarr[i][j]= (i) * (j);6                 document.write (myarr[i][j]+ ' &nbsp; ');7             }8 document.write (' <br/>');9}

Statement 2

1 var myarr=[[1,2,3],[4,5,6]];

JS's 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.