Several common methods of javascript array, javascript Array
1. join ()
The Array. join method converts all elements in the Array into strings and concatenates them. The final generated string is returned.
Example:
Var a = [1, 2, 3]
A. join (); => "1, 2, 3"
A. join ("") => "1 2 3"
The Array. join () method is the reverse operation of the String. split method.
2. reverse ()
The Array. reverse () method reverses the order of elements in the Array.
Var a = [1, 2, 3]
A. reverse (). join () => "3, 2, 1"
3. sort ()
The Array. sort () method sorts the elements in the element group and returns the sorted Array.
4. concat ()
The Array. concat () method is created and a new Array is returned. Its elements include the elements of the original Array that calls concat () and every parameter of concat.
Var a = [1, 2, 3];
A. concat () // return [, 5]
5. slice ()
The Array. slice () method returns a fragment or sub-Array of the specified Array. Its Two Parameters specify the start and end positions of the fragment respectively.
Var a = [1, 2, 3, 4, 5]
A. slice () // return [, 3]
A. slice (3) // return [4, 5]
A. slice (1,-1) // return [2, 3, 4]
6. splice ()
The Array. splice () method inserts or deletes elements in an Array. Unlike slice () and concat (), splice () modifies the called Array.
Splice () can delete elements from the array, insert elements into the array, or colleagues to complete these two operations.
Var a = [1, 2, 3, 4, 5, 6, 7, 8]
A. splice (4); // return [,]; a is [,]
A. splice () // Returns [2, 3]; a is []
7. push () and pop ()
The push () and pop () methods allow the use of arrays as stacks.
After the stack is advanced, you will understand it and will not list it.
8. unshift () and shift ()
The behavior of the unshift () and shift () methods is very similar to push () and pop (). The difference is that the former is element in the array header rather than the tail.
Insert and delete operations.
9. toString () and toLocaleString ()
This is not explained.