Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (21 sloc) 692 Bytes

Array.prototype.reverse()

The JavaScript array method .reverse() will reverse the order of the elements within the array.

Syntax

var array = [1, 2, 3, 4, 5];
array.reverse();

Description

.reverse() reverses the index of the elements of an array.

Examples

Use .reverse() to reverse the elements of an array

var array = [1, 2, 3, 4, 5];
console.log(array);
// Console will output 1, 2, 3, 4, 5

array.reverse();

console.log(array);
/* Console will output 5, 4, 3, 2, 1 and
the variable array now contains the set [5, 4, 3, 2, 1] */

Source MDN

Something went wrong with that request. Please try again.