Reverse the elements of an array in place.
The reverse() method reverses the elements of an array in place and returns the reference to the same array. The first element becomes the last and the last becomes the first. This method mutates the original array.
If you need a reversed copy without modifying the original, use toReversed() (ES2023) or spread the array before reversing: [...arr].reverse().
reverse() is commonly used in algorithms, display logic for sorting order toggles, and when processing data that needs to be iterated from end to beginning.
const arr = [1, 2, 3];
arr.reverse(); // [3, 2, 1]
// arr is now [3, 2, 1]