verse() - JavaScript - MDN Web Docs

  • Skip to main content
  • Skip to search
Array.prototype.reverse() Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

  • Learn more
  • See full compatibility
  • Report feedback

The reverse() method of Array instances reverses an array in place and returns the reference to the same array, the first array element now becoming the last, and the last array element becoming the first. In other words, elements order in the array will be turned towards the direction opposite to that previously stated.

To reverse the elements in an array without mutating the original array, use toReversed().

In this article

  • Try it
  • Syntax
  • Description
  • Examples
  • Specifications
  • Browser compatibility
  • See also

Try it

const array = ["one", "two", "three"]; console.log("array:", array); // Expected output: "array:" Array ["one", "two", "three"] const reversed = array.reverse(); console.log("reversed:", reversed); // Expected output: "reversed:" Array ["three", "two", "one"] // Careful: reverse is destructive -- it changes the original array. console.log("array:", array); // Expected output: "array:" Array ["three", "two", "one"]

Syntax

jsreverse()

Parameters

None.

Return value

The reference to the original array, now reversed. Note that the array is reversed in place, and no copy is made.

Description

The reverse() method transposes the elements of the calling array object in place, mutating the array, and returning a reference to the array.

The reverse() method preserves empty slots. If the source array is sparse, the empty slots' corresponding new indices are deleted and also become empty slots.

The reverse() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable.

Examples

Reversing the elements in an array

The following example creates an array items, containing three elements, then reverses the array. The call to reverse() returns a reference to the reversed array items.

jsconst items = [1, 2, 3]; console.log(items); // [1, 2, 3] items.reverse(); console.log(items); // [3, 2, 1]

The reverse() method returns the reference to the same array

The reverse() method returns reference to the original array, so mutating the returned array will mutate the original array as well.

jsconst numbers = [3, 2, 4, 1, 5]; const reversed = numbers.reverse(); // numbers and reversed are both in reversed order [5, 1, 4, 2, 3] reversed[0] = 5; console.log(numbers[0]); // 5

In case you want reverse() to not mutate the original array, but return a shallow-copied array like other array methods (e.g., map()) do, use the toReversed() method. Alternatively, you can do a shallow copy before calling reverse(), using the spread syntax or Array.from().

jsconst numbers = [3, 2, 4, 1, 5]; // [...numbers] creates a shallow copy, so reverse() does not mutate the original const reverted = [...numbers].reverse(); reverted[0] = 5; console.log(numbers[0]); // 3

Using reverse() on sparse arrays

Sparse arrays remain sparse after calling reverse(). Empty slots are copied over to their respective new indices as empty slots.

jsconsole.log([1, , 3].reverse()); // [3, empty, 1] console.log([1, , 3, 4].reverse()); // [4, 3, empty, 1]

Calling reverse() on non-array objects

The reverse() method reads the length property of this. It then visits each property having an integer key between 0 and length / 2, and swaps the two corresponding indices on both ends, deleting any destination property for which the source property did not exist.

jsconst arrayLike = { length: 3, unrelated: "foo", 2: 4, 3: 33, // ignored by reverse() since length is 3 }; console.log(Array.prototype.reverse.call(arrayLike)); // { 0: 4, 3: 33, length: 3, unrelated: 'foo' } // The index 2 is deleted because there was no index 0 present originally // The index 3 is unchanged since the length is 3

Specifications

Specification
ECMAScript® 2026 Language Specification# sec-array.prototype.reverse

Browser compatibility

See also

  • Polyfill of Array.prototype.reverse in core-js
  • es-shims polyfill of Array.prototype.reverse
  • Indexed collections guide
  • Array
  • Array.prototype.join()
  • Array.prototype.sort()
  • Array.prototype.toReversed()
  • TypedArray.prototype.reverse()

Help improve MDN

Was this page helpful to you? Yes No Learn how to contribute

This page was last modified on Jul 20, 2025 by MDN contributors.

View this page on GitHub • Report a problem with this content Filter sidebar
  1. Standard built-in objects
  2. Array
  3. Constructor
    1. Array()
  4. Static methods
    1. from()
    2. fromAsync()
    3. isArray()
    4. of()
  5. Static properties
    1. [Symbol.species]
  6. Instance methods
    1. at()
    2. concat()
    3. copyWithin()
    4. entries()
    5. every()
    6. fill()
    7. filter()
    8. find()
    9. findIndex()
    10. findLast()
    11. findLastIndex()
    12. flat()
    13. flatMap()
    14. forEach()
    15. includes()
    16. indexOf()
    17. join()
    18. keys()
    19. lastIndexOf()
    20. map()
    21. pop()
    22. push()
    23. reduce()
    24. reduceRight()
    25. reverse()
    26. shift()
    27. slice()
    28. some()
    29. sort()
    30. splice()
    31. toLocaleString()
    32. toReversed()
    33. toSorted()
    34. toSpliced()
    35. toString()
    36. unshift()
    37. values()
    38. with()
    39. [Symbol.iterator]()
  7. Instance properties
    1. length
    2. [Symbol.unscopables]
  8. Inheritance
  9. Object/Function
  10. Static methods
    1. apply()
    2. bind()
    3. call()
    4. toString()
    5. [Symbol.hasInstance]()
  11. Static properties
    1. displayName Non-standard
    2. length
    3. name
    4. prototype
    5. arguments Non-standard Deprecated
    6. caller Non-standard Deprecated
  12. Instance methods
    1. __defineGetter__() Deprecated
    2. __defineSetter__() Deprecated
    3. __lookupGetter__() Deprecated
    4. __lookupSetter__() Deprecated
    5. hasOwnProperty()
    6. isPrototypeOf()
    7. propertyIsEnumerable()
    8. toLocaleString()
    9. toString()
    10. valueOf()
  13. Instance properties
    1. __proto__ Deprecated
    2. constructor

Tag » How To Reverse A String Javascript