Home > Article > Web Front-end > Summary of Javascript array operation functions_javascript skills
In fact, push and pop are usually used more often, but I still write them down for later use.
shift : delete the first item of the original array and return the value of the deleted element; if the array is empty, return undefined
unshift : Add parameters to the beginning of the original array and return the length of the array
Note: The test return value under IE6.0 is always undefined, and the test return value under FF2.0 is 7, so the return value of this method is unreliable. When the return value is needed, splice can be used instead of this method. This article comes from www.45it.com
pop : Delete the last item of the original array and return the value of the deleted element; if the array is empty, return undefined
push : Add parameters to the end of the original array and return the length of the array
concat : Returns a new array, which is composed of adding parameters to the original array
splice (start,deleteCount,val1,val2,...): Delete deleteCount items from the start position and insert val1, val2,...
-------------------------------------------------- ----
Detailed explanation of splice:
The splice function removes one or more elements from an array, inserts a new element at the position of the removed element if necessary, and returns the removed element.
arrayObj.splice( start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
arrayObj is a required option. An Array object.
Start is a required option. Specifies the starting position to remove elements from the array, starting from 0.
deleteCount is required. The number of elements to remove.
item1, item2,. . ., itemN is required. A new element to be inserted at the location of the removed element.
The splice function method in JavaScript can modify arrayObj by removing a specified number of elements starting from the start position and inserting new elements. The return value is a new Array object consisting of the removed elements.
-------------------------------------------------- ----
reverse : Reverse the array
sort (orderfunction): Sort the array according to the specified parameters
slice (start,end): Returns a new array composed of items between the specified start index and the end index in the original array
join (separator): Combine the elements of the array into a string, with separator as the separator. If omitted, the default comma is used as the separator
The above is the entire content of this article, I hope you guys will like it.