Skip to main content

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