JavaScript Array reverse() method

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

The first array element becomes the last, and the last array element becomes the first.

The reverse() method overwrites the original array.

The reverse() method reverses an array in place.

This method returns the reference of the reversed original array.

In this tutorial, we’ll take a look at how to reverse an array in JavaScript

Syntax

array.reverse();

Parameters: This method does not accept any parameter.

Return Value

The reversed array.

Examples

const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
// expected output: "array1:" Array ["one", "two", "three"]

const reversed = array1.reverse();
console.log('reversed:', reversed);
// expected output: "reversed:" Array ["three", "two", "one"]

// Careful: reverse is destructive -- it changes the original array.
console.log('array1:', array1);
// expected output: "array1:" Array ["three", "two", "one"]
const a = [1, 2, 3];

console.log(a); // [1, 2, 3]

a.reverse();

console.log(a); // [3, 2, 1]

Keep in mind that the reverse method will also modify the original array.

let numbers = [1, 2, 3, 4, 5];
let reversedNumbers = numbers.reverse();

console.log(reversedNumbers);
// [5, 4, 3, 2, 1]

console.log(numbers);
// [5, 4, 3, 2, 1]