Skip to main content

What does toReversed() do?

The toReversed() method is a new, safe counterpart to the older reverse() method, added in the ECMAScript 2023 (ES14) standard.

What it does

toReversed() returns a new array in which the elements are in reverse order, while the original array is not changed.

Example:

javascript
const arr = [1, 2, 3]; const reversed = arr.toReversed(); console.log(reversed); // [3, 2, 1] console.log(arr); // [1, 2, 3] - the original stayed the same

Unlike reverse(), which mutates the array, toReversed() makes a clean (immutable) copy.

Comparison with reverse()

MethodChanges the original arrayReturns
reverse()YesThe same array (mutated)
toReversed()NoA new array (reversed)

Comparison example:

javascript
const a = [1, 2, 3]; const b = a.reverse(); console.log(a); // [3, 2, 1] - changed console.log(b); // [3, 2, 1] - the same reference const c = a.toReversed(); console.log(c); // [1, 2, 3] - a new array console.log(a); // [3, 2, 1] - the original is untouched

When to use it

  • When you need to safely reverse an array without damaging the original.
  • Great for functional and reactive programming, where it's important not to mutate data (for example, in React or Redux).

Briefly:

What it doesCreates a reversed copy of the array
Changes the original arrayNo
ReturnsA new array
Added inECMAScript 2023
Example[1, 2, 3].toReversed() -> [3, 2, 1]

JavaScript added a whole family of safe counterparts.

New methodOld mutating counterpartWhat it does
toReversed()reverse()Reverses the array
toSorted()sort()Sorts without changing the original
toSpliced()splice()Returns a modified copy
with()direct assignment by indexReturns a copy with a replaced element

Summary: toReversed() is a non-mutating way to reverse an array, introduced in newer versions of JavaScript (ES2023).

Safe, clean, predictable. Does not change the original array.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.