tail()
tail<
T>(array):T[]
Gets all but the first element of array.
DEPRECATED
Use array.slice(1) directly instead.
Reason:
Native equivalent method now available
Type Parameters
T: T
The type of elements in the array.
Parameters
array: T[]
The array to query.
Returns: T[]
A new array with all elements except the first.
See Also
Since
2.0.0
Also known as
drop (Remeda) · tail (Lodash, es-toolkit, Ramda, Effect) · ❌ (Radashi, Modern Dash, Antfu)
Example
const numbers = [1, 2, 3, 4, 5];
// ❌ Deprecated approach
const rest = tail(numbers);
console.log(rest); // [2, 3, 4, 5]
// ✅ Recommended approach
const restNative = numbers.slice(1);
console.log(restNative); // [2, 3, 4, 5]
How it works?
Gets all but the first element of array.
Deprecated: Use array.slice(1) directly.
Native Equivalent
// ❌ tail(arr)
// ✅ arr.slice(1)
Use Cases
Get all but first element 📌
Get array without the first element.
const items = [1, 2, 3, 4, 5];
items.slice(1);
// => [2, 3, 4, 5]
Skip header row
Process data rows, skipping the header.
const csvRows = [["name", "age"], ["Alice", 30], ["Bob", 25]];
csvRows.slice(1);
// => [["Alice", 30], ["Bob", 25]]
Get remaining items
Get unprocessed items after the first.
const queue = [current, ...pending];
queue.slice(1);
// => pending items