Concat ()
Concatenate two or more arrays and return results
VaRA = [1, 2, 3];VaRB = A. Concat (6, 7); Console. Log ();//[1, 2, 3]Console. Log (B );//[1, 2, 3, 6, 7]
Join (STR)
All elements of the array are separated by STR, which is separated by commas by default.
VaRA = [1, 2, 3]VaRB = A. Join ('|'); Console. Log ();//[1, 2, 3]Console. Log (B );//"1 | 2 | 3"
Pop ()
Delete and return the value of the last element of the array
VaRA = [1, 2, 3];VaRB =A. Pop (); console. Log ();//[1, 2]Console. Log (B );//3
Push ()
Add one or more elements to the end of the array and return the length of the new array.
VaRA = [1, 2, 3];VaRB = A. Push ('4', '5'); Console. Log ();//[1, 2, 3, 4, 5]Console. Log (B );//5
Reverse ()
Reverse the order of elements in the array
VaRA = [1, 2, 3, 4, 5];VaRB =A. Reverse (); console. Log ();//[5, 4, 3, 2, 1]Console. Log (B );//[5, 4, 3, 2, 1]
Shift ()
Delete and return the first element of the array
VaRA = [1, 2, 3];VaRB =A. Shift (); console. Log ();//[2, 3]Console. Log (B );//1
Slice (START, end)
Returns the selected element from an existing array.
VaR A = [1, 2, 3, 4, 5 ]; VaR B = A. Slice (0,-1 ); VaR C = A. Slice (1, 3 ); VaR D = A. Slice (1 ); VaR E = A. Slice (2,-2 ); VaR F = A. Slice (3,1 ); Console. Log (); // [1, 2, 3, 4, 5] Console. Log (B );// [1, 2, 3, 4] Console. Log (C ); // [2, 3] Console. Log (d ); // [2, 3, 4, 5] Console. Log (E ); // [3] Console. Log (f ); // []
Sort (func)
Sorts arrays by specified parameters
Note:Func must return a value.
Negative value. The first parameter is smaller than the second parameter and is placed first.
Zero, equal.
A positive value. The first parameter is later than the second parameter.
var A = [000000, ]; var B = . sort (); console. log (a); /// [1, 10, 2, 3] console. log (B); /// , 2, 3] var num = function (x, y) { return X- Y ;} var C = . sort (Num); console. log (a); /// [1, 2, 3, 10] console. log (c); /// , 3, 10]
Splice (START, deletecount, val1, val2 ,···)
Removes one or more elements from an array, inserts a new element at this position, and returns the removed element.
VaRA = [1, 2, 3, 4, 5];VaRB = A. splice (2,2, 7,8); Console. Log ();//[1, 2, 7, 8, 5]Console. Log (B );//[3, 4]
Unshift (val1, val2 ,···)
Insert the specified element into the starting position of the array and return the new length.
VaRA = [1, 2, 3];VaRB = A. unshift (-2,-1); Console. Log ();//[-2,-,]Console. Log (B );//5
Tostring ()
Convert the elements of the array into strings, separate them with commas, and connect them.
VaRA = [1, 2, 3, 4, 5];VaRB =A. tostring (); console. Log ();//[1, 2, 3, 4, 5]Console. Log (B );//"1, 2, 3, 4, 5"