W3cubDocs

/JavaScript

TypedArray.prototype.reverse()

The reverse() method of TypedArray instances reverses a typed array in place and returns the reference to the same typed array, the first typed array element now becoming the last, and the last typed array element becoming the first. In other words, elements order in the typed array will be turned towards the direction opposite to that previously stated. This method has the same algorithm as Array.prototype.reverse().

Try it

Syntax

js
reverse()

Parameters

None.

Return value

The reference to the original typed array, now reversed. Note that the typed array is reversed in place, and no copy is made.

Description

See Array.prototype.reverse() for more details. This method is not generic and can only be called on typed array instances.

Examples

Using reverse()

js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse();

console.log(uint8); // Uint8Array [3, 2, 1]

Specifications

Browser compatibility

Desktop Mobile Server
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android Deno Node.js
reverse 45 12 37 32 10 45 37 32 10 5.0 45 1.0 4.0.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/reverse