docs/reference/compat/array/tail.md
::: warning Please use tail from es-toolkit
This tail function operates slowly due to handling null or undefined.
Please use the faster and modern tail from es-toolkit instead.
:::
Returns all elements of an array except the first one.
const result = tail(array);
tail(array)Use tail when you want to create a new array containing all elements except the first one from the input array. If the input array is empty or has only one element, it returns an empty array.
import { tail } from 'es-toolkit/compat';
// Remove the first element from a number array.
tail([1, 2, 3]);
// Returns: [2, 3]
// Remove the first element from a string array.
tail(['a', 'b', 'c']);
// Returns: ['b', 'c']
// Array with only one element.
tail([1]);
// Returns: []
// Empty array.
tail([]);
// Returns: []
null or undefined is treated as an empty array.
import { tail } from 'es-toolkit/compat';
tail(null); // []
tail(undefined); // []
array (ArrayLike<T> | null | undefined): The array to remove the first element from.(T[]): Returns a new array containing all elements except the first one.