Mozilla.com

Summary

Transposes the elements of an array: the first array element becomes the last and the last becomes the first.

Method of Array
Implemented in: JavaScript 1.1, NES 2.0
ECMA Version: ECMA-262

Syntax

array.reverse();

Parameters

None.

Description

The reverse method transposes the elements of the calling array object in place, mutating 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

Page last modified 15:01, 5 Aug 2007 by Mgjbot

Tags:

Files (0)