• Skip to main content
  • Skip to search
  • Skip to select language
HTML

Structure of content on the web

  • Web APIs

    Interfaces for building web applications

  • Learn
    • CSS

      Learn to style content using CSS

    • Overview

      A customized MDN experience

    • FAQ

      Frequently asked questions about MDN Plus

  • HTTP Observatory

    Scan a website for free

  • JavaScript
  • Array.prototype.reverse()
      • Deutsch
      • Español
      • Français
      • 日本語
      • 한국어
      • Português (do Brasil)
      • Русский
      • 中文 (简体)
      • 正體中文 (繁體)

    In this article

    • Try it
    • Syntax
    • Description
    • Examples
    • Specifications
    • Browser compatibility
    • See also
    1. Array.from()
    2. Array[Symbol.species]
  • Instance methods
    1. Array.prototype.entries()
    2. Array.prototype.find()
    3. Array.prototype.flat()
    4. Array.prototype.indexOf()
    5. Array.prototype.map()
    6. Array.prototype.reduceRight()
    7. Array.prototype.some()
    8. Array.prototype.toReversed()
    9. Array.prototype.unshift()
    10. Array: length
    11. Function.prototype.bind()
    12. Function: displayName Non-standard
    13. Function.prototype.arguments Non-standard Deprecated
    14. Function.prototype.caller Non-standard Deprecated
  • Instance methods
    1. Object.prototype.__defineGetter__() Deprecated
    2. Object.prototype.__defineSetter__() Deprecated
    3. Object.prototype.__lookupGetter__() Deprecated
    4. Object.prototype.__lookupSetter__() Deprecated
    5. Object.prototype.toLocaleString()
    6. Object.prototype.__proto__ Deprecated
    7. Learn more
    8. See full compatibility
    9. 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().

  • Try it

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

    Syntax

    js
    reverse()
    

    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 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.

    js
    const 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.

    js
    const 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 spread syntax or Array.from().

    js
    const 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.

    js
    console.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.

    js
    const 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

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant