Array.reverse

Did you know that you can read content offline by using one of these tools? If you would like to read offline MDN content in another format, let us know by commenting on Bug 665750.

Dash App

Redirected from Array.reverse Redirect 1

Summary

Reverses an array in place.  The first array element becomes the last and the last becomes the first.

Method of Array
Implemented in JavaScript 1.1
ECMAScript Edition ECMAScript 1st Edition

Syntax

array.reverse()

Parameters

None.

Description

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

Examples

Example: Reversing the elements in an array

The following example creates an array myArray, containing three elements, then reverses the array.

var myArray = ["one", "two", "three"];
myArray.reverse();

This code changes myArray so that:

  • myArray[0] is "three"
  • myArray[1] is "two"
  • myArray[2] is "one"

See Also

join, sort

Tags (2)