Introduction to the array object example of Javascript development 3

Source: Internet
Author: User

Var a = new Array ();
If the definition is as follows: a [3] = "a"; alert (a. length) 4 is 1,
If yes, but no value is assigned, an undefined (alert (a [0]) is returned.

Create an array:
Copy codeThe Code is as follows:
Arr = []; // Yes, an air Bracket
// It is almost equivalent to the following sentence
Arr = new Array (); var a = new Array (1, "n", 3, "m", 5, "m", 8 );
Var a = []; // defines an empty array
Var a = new Array (2); // defines an Array with a length of 2.
Var a = [2]; defines an array with an initial value of 2
Var a = [1, 2, 2, 3, 4, 4];

Add or delete elements to an array)
Copy codeThe Code is as follows:
Var arr = [4545,5456, 64646];
Arr. push (); // append two elements to the end of the array
Delete arr [2]; // delete each of the three elements directly, but the position is retained, indicating that the length has not changed, so that we can continue to access the elements in the original position.
Use of the join method in the array: Purpose:
Var arr = [1, 2, 4];
Alert (arr. join ("#") 1 #2 #3 #4

Array Performance Improvement:
Copy codeThe Code is as follows:
Var startA = new Date (). getTime ();
Var s = ["start"];
For (var I = 0; I <999999; I ++)
{
S. push ("ABC ");
}
S. join ("");
Alert (new Date (). getTime ()-startA );
StartA = new Date (). getTime ();
// Var arr = [];
Var s = "start ";
For (var I = 0; I <999999; I ++)
{
S + = "ABC ";
}
Alert (new Date (). getTime ()-startA );

Related Article

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.