.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.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours