Javascript reverse array method

Reverse

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

Syntax

array.reverse()

Example

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”
DOWNLOAD SOLUTION HERE