reverse

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

Applies to

Array

Syntax

reverse()

Parameters

None

Description

The reverse method transposes the elements of the calling array object.

Examples

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

myArray = new Array("one", "two", "three")
myArray.reverse()

The output is as follows

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

See also

Array: join, Array: sort