Skip to content

fillAll

The fillAll() function replaces all the elements of an array with a single value and returns the result without altering the input.

Interactive example

Syntax

Classic signature

typescript
function fillAll<
	GenericElement extends unknown 
>(
	input: readonly unknown[],
	element: GenericElement
): GenericElement[]

Curried signature

typescript
function fillAll<
	GenericElement extends unknown
>(
	element: GenericElement
): (input: readonly unknown[]) => GenericElement[]

Parameters

  • input: Source array.
  • element: Value to copy at each position (the output type is based on this value).

Return value

A new array where all elements equal element, typed from that value. The initial array remains unchanged.

See also

  • fill - Limits filling to a section
  • set - Changes a single specific index

Sources

Released under the MIT license.