typedArray.toReversed() is the copying version of reverse(). It returns a new typed array of the same type with the elements in reverse order, and the original is left exactly as it was. The new array has its own ArrayBuffer, so changing one never changes the other. It was added in ES2023, together with toSorted() and with().
Remember
typedArray.toReversed() → NEW typed array, reversed
const a = new Uint8Array([1, 2, 3]);
const b = a.toReversed(); // b: 3 2 1
a // still 1 2 3
b.buffer !== a.buffer // true
reverse() → changes the original
toReversed() → leaves it alone
Syntax
toReversed() takes no arguments. Call it on any typed array.
JavaScript
typedArray.toReversed()
Call
What it does
ta.toReversed()
Get a new typed array with the elements in reverse order.
ta.toReversed().join(" ")
Reverse a copy and turn it into text for printing.
for (const v of ta.toReversed())
Walk the data from the last element to the first without changing it.
Added in ES2023 for all 11 typed array types. Older browsers do not have it; use ta.slice().reverse() there.
Library declarations
JavaScript
TypedArray.prototype.toReversed() // returns a new typed array
// same type and length as the original, new ArrayBuffer
// the original typed array is not modified
Parameters
Parameter
Description
(none)
toReversed() has no parameters. Extra arguments are ignored.
Return Value
Return Value
Description
TypedArray
A new typed array of the same type and length, in reverse order. It does not share memory with the original.
JavaScript Examples
Example 1 — Reverse Without Touching the Original
Four steps of a path are stored as bytes. We want the way back, but we also want to keep the way forward.
A loop over the copy.for...of walks the reversed copy, so it prints 150 first and 120 last.
The history stays oldest first.history.at(-1) still returns 150, because the last element of the original did not move.
Reverse twice, get home. Reversing a copy of a copy gives the first order again, here 120 135 150.
Compatibility
Browser & Runtime Support
TypedArray.prototype.toReversed() was added in ES2023, together with toSorted() and with().
✓ Baseline · ES2023
TypedArray.prototype.toReversed()
Supported in recent versions of Chrome, Edge, Firefox, Safari, and Node.js.
93%Recent browsers only
Google ChromeChrome 110 and newer
Full support
Mozilla FirefoxFirefox 115 and newer
Full support
Apple SafariSafari 16 and newer
Full support
Microsoft EdgeEdge 110 and newer
Full support
Node.jsNode.js 20 and newer
Supported
DenoRecent versions
Supported
Internet ExplorerNo support
Not supported
toReversed()Recent browsers
Bottom line: Use it in recent browsers and Node.js 20 or newer. For older ones, write ta.slice().reverse(), which does the same job.
Frequently Asked Questions
reverse() flips the original and returns it. toReversed() builds a new typed array in reverse order and leaves the original alone.
It is an ES2023 method: Chrome 110, Edge 110, Firefox 115, Safari 16, and Node.js 20. Older versions throw a TypeError, so use slice().reverse() there.
No. It returns a typed array of the same type as the original, for example a Uint8Array stays a Uint8Array.
No. The copy has its own ArrayBuffer, so writing to one array never changes the other.
Yes. It returns a new empty typed array of the same type, with length 0.