JavaScript development of three Array Object Example Introduction _ Basic Knowledge

Source: Internet
Author: User

var a=new Array ();
If this definition: a[3]= "a"; Alert (A.length) 4 instead of 1,
If defined, but not assigned, returns a undefined (alert (a[0))

To create an array :

Copy Code code as follows:

arr = [];//Yes, an aerial bracket
is almost equivalent to the following sentence
arr = new Array (); var a=new array (1, "N", 3, "M", 5, "M", 8);
var a=[]; Define an empty array
var a=new Array (2); Defines an array of length 2
var a=[2]; Defines an array with an initial value of 2
var a=[1,2,2,2,3,4,4,4];

Add to Array, delete element (Push,delete)
Copy Code code as follows:

var arr=[4545,5456,64646];
Arr.push (55,88); Append two elements to the end of an array
The delete arr[2];//directly deletes every three elements, but the position remains, indicating that the length has not changed, so that we can continue to access the elements of the original location.
Use of join methods in arrays: function:
var arr=[1,2,3,4];
Alert (Arr.join ("#")) 1#2#3#4

improvement of array performance
Copy Code code 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.