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/fp/initial.md.

initial (Functional Programming) es-toolkit

Creates a function that returns all values except the last one. Use it with pipe.

const result = pipe(array, initial());
Info

Prefer the original es-toolkit initial in ordinary code. Use this fp variant when composing transformations with pipe.

Usage

initial returns a new array without the last value of the piped array.

import { initial, pipe } from 'es-toolkit/fp';

pipe([1, 2, 3], initial()); // => [1, 2]

Parameters

This function takes no arguments; call it as initial().

Returns

A function that maps a readonly T[] to all values except the last one.

(array: readonly T[]) => 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.