var a=new Array();
If it is defined like this: a[3]="a"; alert(a.length) 4 is 1,
If it is defined but not assigned, then Return an undefined (alert(a[0]))
Create array:
arr = [];//Yes, an air 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); //Define an array with a length of 2
var a=[2]; Define an array with an initial value of 2
var a=[1,2,2,2,3,4 ,4,4];
Add and delete elements to the array (push, delete)
var arr=[4545,5456,64646];
arr.push(55,88); //Append two elements to the end of the array
delete arr[2];//Every three elements are deleted directly, but the position is still retained, indicating that the length has not changed, so that we can continue to access the elements at the original position.
Usage of join method in array: Function:
var arr=[1,2,3,4];
alert(arr.join("#")) 1#2#3#4
Improvement of array performance:
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);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn