Reprint Address: http://blog.sina.com.cn/s/blog_60e74b5d01017og5.html
1. Create array var array = new Array ();
var array = new Array (size);//Specify the length of the array
var array = new Array (item1,item2......itemn);//Create an array and assign a value
2, take value, assign value
var item = array[index];//Gets the value of the specified element
Array[index] = value;//Assign value to the specified element
3. Add new elements
Array.push (ITEM1,ITEM2......ITEMN);//Add one or more elements to the array, returning the length of the new array
Array.unshift (ITEM1,ITEM2......ITEMN);//Adds one or more elements to the beginning of the array, the original element position is automatically moved back, and the length of the new array is returned
Array.splice (START,DELCOUNT,ITEM1,ITEM2......ITEMN);//Remove delcount elements from start position, then insert one or more new elements from start position
4, delete elements
Array.pop ()//deletes the last element and returns the element
Array.shift ()//deletes the first element, the array element position is automatically moved forward, and the deleted element is returned
Array.splice (Start,delcount);//Remove delcount elements from start position
5, the integration of the array, interception
Array.slice (start,end);//Returns a portion of an array as an array, noting that the end-corresponding element is not included, if the end will copy all elements after start
Array.concat (array1,array2);//to stitch multiple arrays into an array
6, sorting the array
Array.reverse ();//Array inversion
Array.Sort ();//array sort, return array address
7, the array of the string
Array.join (separator);//connect array reason with separator
That's all you've got. The method for deleting an array element is not found. So I looked up some information and found a solution.
Removing an array element requires extending the array prototype prototype.
Array.prototype.del=function (index) {
if (isNaN) | | Index>=this.length) {return
false;
}
for (Var i=0,n=0;i
if (This[i]!=this[index]) {
this[n++]=this[i];
}
}
this.length-=1;
};