Back to Es Toolkit

length (Functional Programming)

docs/fp/reference/length.md

1.49.0669 B
Original Source

length (Functional Programming)

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

typescript
const result = pipe(array, length());

::: info

This helper is specific to es-toolkit/fp. Use it when you want this operation as part of a pipe pipeline.

:::

Usage

length returns the number of values in the piped array.

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

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

Parameters

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

Returns

((array: readonly T[]) => number): A function that maps a readonly T[] to its length.