Array.reverse()

JavaScript 1.1+, ECMAScript 1.0+, JScript 3.0+ Nav3+, NES3+, IE 4+ Syntax

							array.reverse()

Description

The reverse() method reverses the order of the elements in the array according to the array index numbers.

Example

Listing 6.54 creates an array representing a line of people. The reverse() method is called to reverse the order of the names so that Polly is the first element, Leslie is the second element, and Cheryl is the last element.

Listing 6.54 Reversing Element Positions in an Array with the reverse() Method
 <script language="JavaScript"> <!–– Hide //Create an array of names representing people in a grocery store line lineOfPeople = new Array("Cheryl","Leslie","Polly"); lineOfPeople.reverse(); //Reverse the items ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.