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/last.md.

last (Functional Programming) es-toolkit

Creates a function that returns the last value of an array. Use it with pipe.

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

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

Usage

last returns the last value in the piped array. If the array is empty, it returns undefined.

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

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

pipe([], last()); // => undefined

Parameters

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

Returns

A function that maps a readonly T[] to its last value.

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