Array array operation

Array array operation

Array array operation

Function

Array prototype function provides add, delete, modify, sort, slice, flatten, deep copy and high-order traversal capabilities.

API List

APIDescription
Array.lenReturns the number of array elements.
Array.to_stringSerialize an array into a JSON string.
Array.joinSplice the array elements into a string according to the delimiter.
Array.eachTraverse the array and execute callbacks.
Array.popDelete and return the last element of the array.
Array.firstReturns the first element of the array; returns empty for an empty array.
Array.lastReturns the last element of the array; returns empty for an empty array.
Array.atRead elements by subscript, and support reading negative numbers from the tail.
Array.pushAppend one or more elements to the end of the array.
Array.shiftDelete and return the first element of the array.
Array.unshiftInsert one or more elements into the beginning of the array.
Array.insertInsert one or more elements at the specified index.
Array.sortSort an array. When no callback is passed, the order is sorted by the element string value; when the callback is passed, the order is determined by the number returned by the callback.
Array.reverseReverse the order of array elements.
Array.sliceCopy the array fragment according to the starting and ending indexes.
Array.spliceRemoves the specified range from the array and inserts new elements.
Array.concatConsolidate the current array and subsequent parameters. Array parameters are expanded one level, and non-array parameters are appended element by element.
Array.containsDetermine whether the array contains the specified value.
Array.index_ofReturns the index of the first occurrence of the specified value.
Array.last_index_ofReturns the index of the last occurrence of the specified value.
Array.findReturns the first element for which the callback result is true.
Array.find_indexReturns the index of the first element for which the callback result is true.
Array.find_lastReturns the first element from right to left for which the callback result is true.
Array.find_last_indexReturns the first element index from right to left for which the callback result is true.
Array.everyDetermine whether all elements in the array make the callback result true.
Array.someDetermine whether there is an element in the array and make the callback result true.
Array.filterFilter elements so that the callback result is true.
Array.mapTraverse the array and form a new array with the callback return value.
Array.reduceAccumulate array elements from left to right.
Array.reduce_rightAccumulate array elements from right to left.
Array.fillFills a range of the array with the specified value.
Array.flatFlatten a nested array by depth.
Array.flat_mapFirst map and then expand the mapping result by depth 1.
Array.keysReturns an array of array subscripts.
Array.valuesReturns a shallow copy of the array.
Array.entriesReturns an array of entries in the form [index, value].
Array.cloneReturns an array deep copy.
Array.deleteDelete the element at the specified index.
Array.remove_atDelete and return the element with the specified subscript, supporting negative subscripts.
Array.clearClear the array and return the original array.
Array.is_emptyDetermine whether the array is empty.
Array.uniqueReturns the new array after deduplication in order of first appearance.
Array.chunkSplit the array into a two-dimensional array according to the specified size.

Examples

Notes

  • push, pop, shift, unshift, insert, sort, reverse, splice, fill, delete, remove_at, clear will modify the original array.
- slice, concat, map, filter, flat, flat_map, clone, values, entries, unique, chunk Return a new array.