Array.prototype.toReversed()
Returns a new array with the elements reversed, without mutating the original.
Syntax
arr.toReversed() Returns
Array — A new array with elements in reverse order.
Examples
const a = [1, 2, 3];
console.log(a.toReversed(), a);
Output
[ 3, 2, 1 ] [ 1, 2, 3 ]
console.log(['a', 'b'].toReversed());
Output
[ 'b', 'a' ]
Notes
The non-mutating version of `reverse`. Equivalent to `[...a].reverse()` but
more concise and explicit about intent.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 110 |
| firefox | 115 |
| safari | 16 |
| edge | 110 |
| node | 20 |