An array of methods based approach
Array Object Properties
Attributes | description |
---|---|
constructor | Returns an array function to create this object references. |
length | Sets or returns the number of elements in the array. |
prototype | It gives you the ability to add properties and methods to an object. |
Array Object Methods
method | 描述 |
---|---|
concat() | Connecting two or more arrays, and returns the result. |
join() | All the elements of the array into a string. Elements separated by the specified delimiter. |
pop() | Remove and return the last element of the array |
push() | Add one or more elements to the end of the array, and returns the new length. |
reverse() | Reverse the order of elements in the array. |
shift() | Removes and returns the first element of the array |
slice() | Returns selected elements from an existing array |
sort() | Of the elements of the array to sort |
splice() | Delete elements, add a new element to the array. |
toSource() | Back to the source code of the object. |
toString() | Converting a string array, and returns the result. |
toLocaleString() | Converting the array to a local array, and returns the result. |
unshift() | Add one or more elements to the beginning of an array and returns the new length. |
valueOf() | Returns an array of object's original value |
var arr = [1,2,3,4,5,6,7,8,9,10];
push()
向数组的末尾添加一个或更多元素,并返回新的长度。
console.log(arr.push(11)); // 11
console.log(arr); // [1,2,3,4,5,6,7,8,9,10,11]
pop()
删除并返回数组的最后一个元素
console.log(arr.pop()); // 11
console.log(arr); // [1,2,3,4,5,6,7,8,9,10]
unshift()
向数组的开头添加一个或更多元素,并返回新的长度。
console.log(arr.unshift(0)); // 11
console.log(arr); // [0,1,2,3,4,5,6,7,8,9,10]
shift()
删除并返回数组的第一个元素
console.log(arr.shift()); // 0
console.log(arr); // [1,2,3,4,5,6,7,8,9,10]