Array.prototype.reverse
Reverses an array in place.
Available since: ES1
Syntax
array.reverse()Return value
ArrayThe same array, now reversed.
Examples
Reverse order:
const numbers = [1, 2, 3];
numbers.reverse();
console.log(numbers);Output:
[
3,
2,
1
]Reversing a string through an array of characters:
console.log([...'hello'].reverse().join(''));Output:
ollehNotes
The method changes the original array. If you still need it in the old order, use toReversed() or [...array].reverse().
See also
- Array.prototype.toReversed — Returns a reversed copy of an array.
- Array.prototype.sort — Sorts the elements of an array.
Related recipes
In the tutorial
- Sorting arrays — How to sort an array in JavaScript: sort, the compare function, sorting numbers, strings and objects, reverse and toSorted.