insert
The insert() function adds a value to the end of an array and returns a new instance. The curried signature first accepts the array (array), then the value (input), which makes composition easier. (This function is similar to push(), but the order of arguments is reversed).
Interactive example
Syntax
Classic signature
typescript
function insert<
GenericElement extends unknown,
>(
input: GenericElement,
array: readonly GenericElement[],
): GenericElement[]Curried signature
typescript
function insert<
GenericElement extends unknown,
>(
array: readonly GenericElement[],
): (input: GenericElement) => GenericElement[]Parameters
input: Value to add at the end of the array.array: Target array.
Return value
A new array containing all original elements followed by input.
