reverse

 

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 (0)

Edit tags
  • No tags

Attachments (0)

 

Attach file