reverse()  Array  instance method JS Home  <<  JS Reference  <<  Array  <<  reverse()

Description

Reverses the order of elements within an array.

Syntax

Signature Description
anArray.reverse()Reverses the order of elements within an array.

Parameters

None.

Examples

The code below creates an array then reverses the elements.


/*
 Create an array of numbers.
 Reverse the array.
 someNumbers = [3, 2, 1] after reverse().
 */

var someNumbers = [1, 2, 3];
someNumbers.reverse();
alert(someNumbers);

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 1 - Arrays

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Array

Class Properties
prototype
Instance Properties
constructor
length
Class Methods
None.
Instance Methods Getters
concat()
join()
slice()
toString()
Instance Methods Setters
pop()
push()
reverse()
shift()
sort()
splice()
unshift()

Statements

Operators