🔃 Reverses the order of elements in an array.

Info

Immutable: This function does not mutate the original array.

Syntax

TypeScript
import { reverse } from '@opentf/std';

reverse<T>(arr: T[] = []): T[]

Parameters

  • arr: The source array.

Returns

A new array with the elements in reverse order.

Examples

TypeScript
reverse([1, 2, 3]) //=> [3, 2, 1]

reverse([{ a: 1 }, { b: 2 }, { c: 3 }])
//=> [
//  {
//    c: 3,
//  },
//  {
//    b: 2,
//  },
//  {
//    a: 1,
//  },
// ]

reverse('Apple') //=> ['e', 'l', 'p', 'p', 'A']

reverse([1, , 3]) //=> [3, undefined, 1]
Last updated on
Edit this page