Skip to content

push ​

The push() function adds one or more elements to the end of the array and returns a new instance, leaving the input intact.

Interactive example ​

Syntax ​

Classic signature ​

typescript
function push<
	GenericElement extends unknown
>(
	input: readonly GenericElement[],
	element: NoInfer<GenericElement>,
	...elements: NoInfer<GenericElement>[]
): GenericElement[]

Curried signature ​

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

Parameters ​

  • input: Source array.
  • element, ...elements: Values to add at the end.

Return value ​

A new array containing all original elements followed by the added elements.

See also ​

  • unshift - Adds to the beginning of the array
  • concat - Merges multiple arrays

Sources ​

Released under the MIT license.