How to reverse a Javascript array

Description

reverse() method reverses the order of items in an array.

Example


var values = [1, 2, 3, 4, 5]; 
values.reverse(); 
console.log(values); //5,4,3,2,1 

reverse() returns a reference to the resulting array.

The code above generates the following result.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window