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