JavaScript reverse() Method
The JavaScript reverse()
method is used to reverse the order of elements in an array. It modifies the original array and does not create a new one. The first element becomes the last and the last becomes the first, and so on.
Syntax
The syntax for the reverse()
method is as follows:
array.reverse()
where array
is the array to be reversed.
Example
Consider the following example:
let fruits = ["apple", "banana", "mango", "orange"];
fruits.reverse();
console.log(fruits);
Output:
["orange", "mango", "banana", "apple"]