Learning about Arrays & arrays

Source: Internet
Author: User
Tags array length

Array:

var attr =array (array length (can not be written))

var attr =array (); It's equivalent to declaring that I'm creating an array.

Attr[key] =value; Key is unique, also known as index value

Attr[0] = "a";

ATTR[1] = "B";

Array

There are three ways to define an array:

①.attr[0] = "a"; Where the index value key is 0 corresponds to a value of a, the index value key is 1 corresponding to the value of B

ATTR[1] = "B";

②.var attr2 =array ("A", "B"); Defines an array attr2 two values of A and B, respectively.

③.var ATTR3 =["A", "B"]; Defines an array ATTR3 two values of A and B, respectively.

var x=attr.length; Defines an x, which is the length of the array.

ABCD.XYZ (); ABCD is the object,. XYZ is the method inside the calling object.

Cases:

var Attr3=array ("A", "B", "C", "D");

var x =attr3.length; The output is 4 output of 4 is X, also defines the length of this array attr3, it is a value

alert (x);

To iterate over an array:

var attr3= Array ("A", "B", "C", "C"); An array attr3 is defined, and its value is A,b,c,c

for (Var i=0;i<attr3.length;i++) {//For loop, the parentheses define an I, which is equivalent to the key within the array attr3, which is the index value, and the range is less than the length of the array.

Alert (Attr3[i]); Use the For loop to output the value of this called Attr3 array when I equals how much.

}

 

Learning about Arrays & arrays

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.