Skip to content

reverse ​

The reverse() method returns a copy of an array with the elements in reverse order, while leaving the initial array intact. Tuples retain exact typing thanks to ReverseTuple.

Interactive example ​

Syntax ​

typescript
function reverse<
	GenericInput extends readonly unknown[]
>(
	input: GenericInput
): GenericInput extends AnyTuple ? ReverseTuple<GenericInput> : GenericInput

Parameters ​

  • input: The array whose order you want to reverse.

Return value ​

A new array containing the same elements but in reverse order. When the input is a tuple, the result exactly reflects the new arrangement of the elements.

See also ​

  • sort - Sorts an array via a comparison function
  • map - Transforms each element independently

Sources ​

Released under the MIT license.