transformation

Array.prototype.reverse

Reverses the order of elements in place and returns the same (mutated) array. Reach for it when you truly want to reverse the source; otherwise use toReversed().

arr.reverse()

Parameters

Parameter Purpose
return value The same array reference, now reversed
mutation Modifies the original array in place (use toReversed for a copy)

Examples

const a = [1, 2, 3]; a.reverse(); console.log(a);

Logs: [3, 2, 1] — original is mutated

console.log(['a','b','c'].reverse());

Logs: ['c', 'b', 'a']

const a = [1,2,3]; const b = a.toReversed(); console.log(a, b);

Logs: [1, 2, 3] [3, 2, 1] — toReversed is the ES2023 non-mutating version

const a = [1, 2, 3]; const b = a.reverse(); console.log(a === b);

Logs: true — reverse returns the same array reference

Gotcha

MUTATES the source. If you also stored the pre-reverse array in a variable, it is now reversed too. Use `toReversed()` (ES2023) for a copy.

Related methods

← All JS array methods · TypeScript vs JavaScript