Skip to content

shift

The shift() function removes the first element of an array and returns a shortened copy. For tuples, the type is updated exactly thanks to ShiftTuple.

Interactive example

Syntax

typescript
function shift<
	const GenericInput extends readonly unknown[]
>(
	input: GenericInput
): GenericInput extends AnyTuple ? ShiftTuple<GenericInput> : GenericInput

Parameters

  • input: Array from which to remove the first element.

Return value

A new array without its first element.

See also

  • unshift - Adds elements to the head
  • pop - Removes the final element

Sources

Released under the MIT license.