JavaScript .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
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours