.toReversed()
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]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.