Array.prototype.toReversed
Returns a reversed copy of an array.
Available since: ES2023
Syntax
array.toReversed()Return value
ArrayA new array in reverse order.
Examples
A copy in reverse order:
const steps = ['one', 'two', 'three'];
console.log(steps.toReversed().join(', '));
console.log(steps.join(', '));Output:
three, two, one
one, two, threeNotes
It is the safe version of reverse(): the original array is not changed.
See also
- Array.prototype.reverse — Reverses an array in place.
- Array.prototype.toSorted — Returns a sorted copy of an array without changing the original.
In the tutorial
- Sorting arrays — How to sort an array in JavaScript: sort, the compare function, sorting numbers, strings and objects, reverse and toSorted.