.toReversed()

codewithfan's avatar
Published Aug 6, 2023
Contribute to Docs

The .toReversed() reverses the elements within the array and returns a new copy of the array.

Syntax

The .toReversed() method does not take any parameters.

array.toReversed();

Example

Reverse the elements within the array without mutating the original array.

const points = [1, 2, 3, 4, 5];
const reversedPoints = points.toReversed();
console.log('Original', points);
console.log('Copy', reversedPoints);
Original [1,2,3,4,5]
Copy [5,4,3,2,1]

All contributors

Contribute to Docs

Learn JavaScript on Codecademy