TypedArray.prototype.toReversed()

The toReversed() method is the copying counterpart of the reverse() method. It returns a new array with the elements in reversed order. This method has the same algorithm as Array.prototype.reverse(). TypedArray is one of the typed array types here.

Syntax

reverse()

Return value

A new typed array containing the elements in reversed order.

Examples

Using toReversed()

const uint8 = new Uint8Array([1, 2, 3]);
const reversedUint8 = uint8.toReversed();
console.log(reversedUint8); // Uint8Array [3, 2, 1]
console.log(uint8); // Uint8Array [1, 2, 3]

Specifications

Specification
ECMAScript Language Specification
# sec-%typedarray%.prototype.toreversed

Browser compatibility

BCD tables only load in the browser

See also