Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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:

olleh

Notes

The method changes the original array. If you still need it in the old order, use toReversed() or [...array].reverse().

See also

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.

Thanks for reading!

Donate to the site — we work hard for you.