For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/tail.md.

tail es-toolkit

Returns a new array consisting of all elements except the first.

const result = tail(arr);

Usage

tail(arr)

Use tail when you want to get all elements except the first from an array. If the array is empty or has only one element, it returns an empty array. It's useful when processing all elements except the first in a stack or queue.

import { tail } from 'es-toolkit/array';

// Exclude the first element from a number array.
const numbers = [1, 2, 3, 4, 5];
tail(numbers);
// Returns: [2, 3, 4, 5]

// Exclude the first element from a string array.
const strings = ['first', 'second', 'third'];
tail(strings);
// Returns: ['second', 'third']

// An array with only one element returns an empty array.
const single = [42];
tail(single);
// Returns: []

It safely handles empty arrays and special cases.

import { tail } from 'es-toolkit/array';

// An empty array returns an empty array.
const empty: number[] = [];
tail(empty);
// Returns: []

// It can also handle nested arrays.
const nested = [
  [1, 2],
  [3, 4],
  [5, 6],
];
tail(nested);
// Returns: [[3, 4], [5, 6]]

// It can also handle object arrays.
const users = [
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob' },
  { id: 3, name: 'Charlie' },
];
tail(users);
// Returns: [{ id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }]

Parameters

arrreadonly T[]required

The array from which to exclude the first element.

Returns

Returns a new array excluding the first element. If the input array is empty or has only one element, it returns an empty array.

T[]
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.