Array method: First, the array method has an array-prototype method, and there are methods that inherit from object objects. This is only a detailed description of the array's prototype method.
(1) Join: Put all the elements in the array into a string. element is delimited by the specified delimiter.
For example, on the console page, do:
= "1:2:3:4"
(2) Push: Adds an entry to the end of the array, and the return value is the new length of the array.
=>[1, 2, 3, 4, 5, 6, 7]
(3) Unshift: Adds an entry to the first of the array, and the return value is the new length of the array.
var a=[1,2,3,4];=>a [1, 2, 3, 4]a.unshift (2,3) =>6a=>[2, 3, 1, 2, 3, 4]
(4) Pop: Delete the end item of the array, the return value is the deleted array item.
var a=[1,2,3,4];=>a [1, 2, 3, 4]a.pop () =>4a=>[1, 2, 3]
(5) Shift: Deletes the beginning item of the array, returning the item that was deleted.
var a=[1,2,3,4];=>a [1, 2, 3, 4]a.shift () =>1a=>[2, 3, 4]
(6) Splice: Deletes any item in the array, the return value is the deleted array item.
For example:
var a=[1,2,3,4];=>a [1, 2, 3, 4]a.splice (+) //starting from 1 bits, deleting 2 bits (splice) to get results [1,4]=>[2, 3]a=>[1, 4]
(7) Slice: Returns a specific element from an existing array.
var a=[1,2,3,4]=>a [1, 2, 3, 4]var b=a.slice (1,3)//starting with subscript, not including the last one, i.e.: Table 1 corresponds to 2, 3 corresponds to 4, but does not contain 4, results [2,3]=>B [2, 3]
(8) Concat: stitching array.
var a=[1,2,3,4];=>a [1, 2, 3, 4]var B=[].concat (a) =>b [1, 2, 3, 4]var B=[5,6].concat (a) =>b [5, 6, 1, 2, 3, 4]
(9) Reverse: reverse.
var a=[1,2,3,4];=>a [1, 2, 3, 4]a.reverse () =>[4, 3, 2, 1]
(Ten) Sort: sort.
var a=[5,2,8,4];=>a.sort () =>[2, 4, 5, 8]
But sort sorts are sorted by binary, for example:
var a=[25,2,8,4];
=
A.sort ()
[2, 25, 4, 8]//Can be seen 25 rows behind 2
The most commonly used methods are listed, and some of them can be consulted:
JavaScript Array (object) methods