ScanSkill

reverse

The reverse() is used to reverse an array.

Syntax

array.reverse()

The reverse() method attaches to the right side of an array with the . operator. The reverse method sorts the items present in the array in descending order.

Example

const numbers = [1, 2, 3];

console.log(numbers.reverse()); // Prints: [ 3, 2, 1 ]

The input array passed through the reverse method was [ 1, 2, 3 ] and the output given was [3, 2, 1].