Push/pop (method of removing elements at the beginning of the array), Unshift/shift (method to add and remove the end of the array)
var arr3 = [' B ', ' C ', ' d '];
Console.log (Arr3.unshift (' a '));//Add an element at the beginning of the array//number of elements in the printed array
Console.log (ARR3);
Console.log (Arr3.push (' e '));//Add an element to the end of the array
Console.log (ARR3);
var str2 = Arr3.shift ();//Remove the beginning of an element and return the element
Console.log (STR2);
Console.log (ARR3);
var str1 = Arr3.pop (); Removes an element at the end and returns the element
Console.log (STR1);
Console.log (ARR3);
There are already two methods in the array that can be used to sort directly: reverse () and sort ().
Reverse ()//reverse Sort
var box = [1,2,3,4,5];
Console.log (Box.reverse ()); Reverse Sort method, returns the sorted array
Console.log (box); The original array is also sorted backwards.
Sort ()//sorting
Sort (function (A, b) {return-A-B;})//from small to large
Sort (function (A, b) {return b-a;}) From the large to the small sort note that this method to pass the parameter does not pass the participant error such as array [1,10,2], after the sort is still [1,10,2]
var box = [4,1,7,3,9,2];
Console.log (function (A, b) {return-A-B}) (Box.sort); Sort from small to large, return sorted array
Console.log (box); The source array is also sorted from small to large.
JavaScript Knowledge points Summary