Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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, three

Notes

It is the safe version of reverse(): the original array is not changed.

See also

In the tutorial

  • Sorting arrays — How to sort an array in JavaScript: sort, the compare function, sorting numbers, strings and objects, reverse and toSorted.

Thanks for reading!

Donate to the site — we work hard for you.