# Array array operation ## Function Array prototype function provides add, delete, modify, sort, slice, flatten, deep copy and high-order traversal capabilities. ## API List | API | Description | | ------ | ------ | | [Array.len](/en/docs/array/len) | Returns the number of array elements. | | [Array.to_string](/en/docs/array/to_string) | Serialize an array into a JSON string. | | [Array.join](/en/docs/array/join) | Splice the array elements into a string according to the delimiter. | | [Array.each](/en/docs/array/each) | Traverse the array and execute callbacks. | | [Array.pop](/en/docs/array/pop) | Delete and return the last element of the array. | | [Array.first](/en/docs/array/first) | Returns the first element of the array; returns empty for an empty array. | | [Array.last](/en/docs/array/last) | Returns the last element of the array; returns empty for an empty array. | | [Array.at](/en/docs/array/at) | Read elements by subscript, and support reading negative numbers from the tail. | | [Array.push](/en/docs/array/push) | Append one or more elements to the end of the array. | | [Array.shift](/en/docs/array/shift) | Delete and return the first element of the array. | | [Array.unshift](/en/docs/array/unshift) | Insert one or more elements into the beginning of the array. | | [Array.insert](/en/docs/array/insert) | Insert one or more elements at the specified index. | | [Array.sort](/en/docs/array/sort) | Sort 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.reverse](/en/docs/array/reverse) | Reverse the order of array elements. | | [Array.slice](/en/docs/array/slice) | Copy the array fragment according to the starting and ending indexes. | | [Array.splice](/en/docs/array/splice) | Removes the specified range from the array and inserts new elements. | | [Array.concat](/en/docs/array/concat) | Consolidate the current array and subsequent parameters. Array parameters are expanded one level, and non-array parameters are appended element by element. | | [Array.contains](/en/docs/array/contains) | Determine whether the array contains the specified value. | | [Array.index_of](/en/docs/array/index_of) | Returns the index of the first occurrence of the specified value. | | [Array.last_index_of](/en/docs/array/last_index_of) | Returns the index of the last occurrence of the specified value. | | [Array.find](/en/docs/array/find) | Returns the first element for which the callback result is true. | | [Array.find_index](/en/docs/array/find_index) | Returns the index of the first element for which the callback result is true. | | [Array.find_last](/en/docs/array/find_last) | Returns the first element from right to left for which the callback result is true. | | [Array.find_last_index](/en/docs/array/find_last_index) | Returns the first element index from right to left for which the callback result is true. | | [Array.every](/en/docs/array/every) | Determine whether all elements in the array make the callback result true. | | [Array.some](/en/docs/array/some) | Determine whether there is an element in the array and make the callback result true. | | [Array.filter](/en/docs/array/filter) | Filter elements so that the callback result is true. | | [Array.map](/en/docs/array/map) | Traverse the array and form a new array with the callback return value. | | [Array.reduce](/en/docs/array/reduce) | Accumulate array elements from left to right. | | [Array.reduce_right](/en/docs/array/reduce_right) | Accumulate array elements from right to left. | | [Array.fill](/en/docs/array/fill) | Fills a range of the array with the specified value. | | [Array.flat](/en/docs/array/flat) | Flatten a nested array by depth. | | [Array.flat_map](/en/docs/array/flat_map) | First map and then expand the mapping result by depth 1. | | [Array.keys](/en/docs/array/keys) | Returns an array of array subscripts. | | [Array.values](/en/docs/array/values) | Returns a shallow copy of the array. | | [Array.entries](/en/docs/array/entries) | Returns an array of entries in the form [index, value]. | | [Array.clone](/en/docs/array/clone) | Returns an array deep copy. | | [Array.delete](/en/docs/array/delete) | Delete the element at the specified index. | | [Array.remove_at](/en/docs/array/remove_at) | Delete and return the element with the specified subscript, supporting negative subscripts. | | [Array.clear](/en/docs/array/clear) | Clear the array and return the original array. | | [Array.is_empty](/en/docs/array/is_empty) | Determine whether the array is empty. | | [Array.unique](/en/docs/array/unique) | Returns the new array after deduplication in order of first appearance. | | [Array.chunk](/en/docs/array/chunk) | Split the array into a two-dimensional array according to the specified size. | ## Examples ```bt items = [1, 2, 3] result = items.map(fn(value) { value * 2 }) // Output: [2,4,6] print result ``` ## 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.