Definition, traversal, and addition of 0513JS arrays

Source: Internet
Author: User

| array
|-Definition method
|--1, New Array ();
|----Empty Array
|------var attr = new Array ();
|------lenght:0
|------_proto_: Array []
|----An array of length
|------var attr new Array (10);
|------lenght:10
|------_proto_: Array []
|----An array with an initial value
|------var attr = new Array ("Zhang San", 20, "male");
|------Array (3) ["Zhang San", 20, "male"]
|------0: "Zhang San"
|------1: "20"
|------2: "Male"
|------Lenght:3
|------_proto_: Array []
|--2, [];
|----Empty Array
|------var attr = [];
|------lenght:0
|------_proto_: Array []
|----An array with an initial value
|------var attr = ["Zhang San", 20, "male"];
|------0: "Zhang San"
|------1: "20"
|------2: "Male"
|------Lenght:3
|------_proto_: Array []

var New Array (); var New Array (5); var New Array ("Zhang San", 20, "male"); var attr = []; var attr = [5]; var attr = ["Zhang San", 20, "Male"];console.log (attr);


|-array traversal
|--1, for Loop
|--2, for (in)

var person = ["John Doe", 28, "male", "unmarried"];  for (var i = 0;i < person.length;i++ ) {    alert (person[i]);} var person = ["John Doe", 28, "male", "unmarried"];  for (var in person ) {    alert (person[i]);}


|-array Additions
|--1, for Loop
|--2,. push

var attr = [];  for (var i = 0;i < 5;i++) {    = i;    Attr.push (i);} alert (attr);

Definition, traversal, and addition of 0513JS 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.