initial es-toolkit
Returns a new array containing all elements except the last one.
Usage
initial(arr)
Use initial when you want to get all elements except the last one from an array. If the array is empty or has only one element, it returns an empty array. This is useful when processing while excluding the end of the array.
It safely handles empty arrays and special cases.
Parameters
arrreadonly T[]required
The array from which to exclude the last element.
Returns
Returns a new array excluding the last element. If the input array is empty or has only one element, it returns an empty array.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.