References

Beginner-friendly references for web development, with live, editable examples.

The JavaScript array.reverse() method

Method JavaScript All modern browsers Updated
Quick answer

The reverse() method flips an array's elements end-to-end, in place, and returns the same array. [1, 2, 3].reverse() becomes [3, 2, 1]. Because it mutates, copy first with [...arr].reverse() if you need to keep the original, or use the newer non-mutating toReversed().

Overview

reverse() turns an array back-to-front: the last element becomes first, the first becomes last. It does this in place and returns the same (now reversed) array, so the return value and the original variable point at the same thing.

That mutation is the gotcha. If you still need the original order, reverse a copy: const flipped = [...arr].reverse() (or arr.slice().reverse()) leaves arr alone. Newer engines also offer toReversed(), which returns a reversed copy without touching the original — the non-mutating version of this method.

It's commonly paired with sort() to get descending order (though sorting with a compare function is usually clearer), and with split()/join() for the classic "reverse a string" one-liner: str.split("").reverse().join("").

Syntax

array.reverse()  // mutates, returns the same array

[1, 2, 3].reverse()           // [3, 2, 1]
[...arr].reverse()            // reversed copy, original kept
arr.toReversed()              // non-mutating (newer)

Example

Live example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
  const original = [1, 2, 3, 4];

  const flipped = [...original].reverse(); // copy, don't mutate

  document.getElementById('out').textContent =
    'original: ' + original.join(', ') + '\n' +
    'reversed: ' + flipped.join(', ');
</script>

Best practices

  • Copy first — [...arr].reverse() — when you must keep the original order.
  • Prefer the non-mutating toReversed() in modern code where available.
  • Reverse a string with str.split("").reverse().join("").
  • For descending sort order, a compare function on sort() is usually clearer than sort-then-reverse.

Frequently asked questions

Does reverse() change the original array?
Yes, it reverses in place. Copy first with [...arr].reverse() or use toReversed() to keep the original.
How do I reverse a string in JavaScript?
Convert it to an array, reverse, and join back: str.split("").reverse().join("").
How do I reverse an array without mutating it?
Use [...arr].reverse() or the newer arr.toReversed(), both of which return a new array.
What does reverse() return?
The same array, now reversed — not a copy.