1. push () method to add one or more elements to the end of the array, and returns the new length
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.push("banana"));
console.log("新数组:"+arr);
Output Results:
2. POP () This method is used to remove and return the last element of the array
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.pop());
console.log("新数组:"+arr);
Output Results:
3. Shift () value of the method used to remove the first element in the array and return the removed element
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.shift());
console.log("新数组:"+arr);
Output Results:
4. the unshift () method to add one or more elements to the beginning of an array, and returns the new length
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.unshift("banana"));
console.log("新数组:"+arr);
Output Results:
5. The splice () method to / add / delete items from the array, and returns the item that was removed
arrayObject.splice(index,howmany,item1,…,itemX)
- index Required. Integer, regulations add / remove items of location, may require the use of a negative position from the end of the array.
- howmany necessary. The number of items to delete. If set to 0, it will not remove items.
- item, ..., itemX optional. New projects added to the array.
Add Item
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.splice(2,0,"banana"));
console.log("新数组:"+arr);
Output:
replace deleted items, delete items returned
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.splice(2,1,"banana"));
console.log("新数组:"+arr);
Output:
Remove items
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log(arr.splice(1,1));
console.log("新数组:"+arr);
Output:
6. The Sort () This method is used to sort the elements of the array
var arr = ['apple','orange','pear','banana'];
console.log("原数组:"+arr);
console.log("新数组:"+arr.sort());
Output:
digital Sort
function sortNumber(a,b)
{
return a - b
}
var arr = ['123','34','66','6','888','9'];
console.log("原数组:"+arr);
console.log("新数组:"+arr.sort(sortNumber));
Output Results:
7. The Reverse () which inverts the order of elements in the array
var arr = ['apple','orange','pear','banana'];
console.log("原数组:"+arr);
console.log("新数组:"+arr.reverse());
Output:
8. The filter () method creates a new array, a new array element in the array is designated by checking all elements meet the conditions.
9. concat The method for connecting two or more arrays. This method does not change the existing array, but only returns a copy of the array is connected.
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log("新数组:"+arr.concat('banana'));
Output:
var arr = ['apple','orange','pear'];
var arr1 = [1,2];
console.log("原数组:"+arr);
console.log("新数组:"+arr.concat(arr1));
Output Results:
10. The Slice This method returns the selected elements from the array prior
var arr = ['apple','orange','pear'];
console.log("原数组:"+arr);
console.log("新数组:"+arr.slice(0,1));
Output: