JavaScript Reference
Array.prototype.reverse()
Flip the order of elements in place. Returns the same array reference.
Last updated: October 2026
Definition: Array.prototype.reverse() reverses the elements of an array in place and returns a reference to the same array. The first element becomes the last, and the last becomes the first [citation:15].
🎬 Live Example
Five reverse patterns. Click any button to see the output.
💡 reverse mutates in place and returns the same array reference.
Basic Syntax
array.reverse()
// No arguments
// Returns the SAME array reference (reversed in place)
// MUTATES the original array
Basic Array Reversal
const nums = [1, 2, 3, 4, 5];
nums.reverse();
// nums: [5, 4, 3, 2, 1]
The Mutation Trap
const original = [1, 2, 3];
const reversed = original.reverse();
console.log(reversed); // [3, 2, 1]
console.log(original); // [3, 2, 1] ← ALSO reversed!
// They are the SAME array reference
Critical: reverse returns the same array, not a copy. If you need the original intact, copy first.
Reverse a String
const str = 'Hello';
// Chain: split → reverse → join
str.split('').reverse().join('');
// 'olleH'
// Reverses characters, not words
Pro tip: This is the classic JavaScript string reversal idiom. Strings are immutable, so you must convert to array first.
Non-Destructive Reverse
const original = [1, 2, 3];
// ✅ Copy first
const reversed = [...original].reverse();
// original: [1, 2, 3]
// reversed: [3, 2, 1]
// ✅ ES2023+ (modern browsers)
const newer = original.toReversed();
Real-World: Newest-First Log
const logs = [];
function addLog(msg) {
logs.push(msg);
}
addLog('start');
addLog('process');
addLog('done');
// Show newest first
const newestFirst = [...logs].reverse();
// ['done', 'process', 'start']
// Or mutate if you don't need original order
logs.reverse();
🎯 reverse vs toReversed vs sort
| Method | Mutates? | Use when |
|---|---|---|
reverse | Yes | In-place reversal |
toReversed | No | Immutable reversal (ES2023+) |
sort | Yes | Ordered sorting (not reversal) |
⚠️ Common Mistakes
- Assuming reverse copies. It mutates and returns the same array. Copy first with spread.
- Calling reverse on a string. Strings are immutable — convert with split('').
- Using reverse as a sort. reverse just flips; it doesn't order.
- React state mutation.
state.reverse()won't trigger re-renders. Use[...state].reverse(). - Forgetting reverse returns the same reference.
arr.reverse() === arris true.
❓ Frequently Asked Questions
What does Array.reverse() do in JavaScript?
Array.reverse() reverses the elements of an array in place and returns a reference to the same array. The first element becomes the last, and the last becomes the first.
Does reverse modify the original array?
Yes. reverse mutates the array in place and returns the same array reference. To reverse without mutating, use toReversed() (ES2023+) or spread: [...arr].reverse().
What is the difference between reverse and toReversed?
reverse mutates the original array and returns it. toReversed returns a new reversed array without modifying the original. Use toReversed when you need immutability.
Does reverse work on strings?
No. Strings are immutable and don't have a reverse method. Convert to an array first: str.split('').reverse().join('').
How do I reverse an array without mutating?
Use spread to create a copy first: [...arr].reverse(). Or use arr.slice().reverse(). Or use toReversed() in modern browsers.