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

toFilled (Functional Programming) es-toolkit

Creates a function that returns a filled copy of an array. Use it with pipe.

const result = pipe(array, toFilled(value, start, end));
Info

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

Usage

toFilled fills a copy of the piped array with value from start up to, but not including, end. It follows Array.prototype.fill index semantics and does not mutate the input array.

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

const array = [1, 2, 3, 4];

pipe(array, toFilled(0, 1, 3)); // => [1, 0, 0, 4]
array; // => [1, 2, 3, 4]

Parameters

valueUrequired

The value to write into the returned array.

startnumber, optionalrequired

The start index. Defaults to 0.

endnumber, optionalrequired

The end index. Defaults to the array length.

Returns

A function that maps a readonly T[] to a filled copy.

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