Horje
What is the use of reverse() method in JavaScript Arrays ?

The reverse() method in JavaScript is used to reverse the order of elements in an array. It modifies the original array and returns the reversed array. This means that the last element becomes the first, the second-to-last becomes the second, and so on.

Example: Here, the reverse() the method is applied to the myArray, resulting in the original order being reversed.

Javascript

let myArray = [1, 2, 3, 4, 5];
 
// Reverse the order of elements in the array
myArray.reverse();
 
console.log(myArray); // Output: [5, 4, 3, 2, 1]

Output

[ 5, 4, 3, 2, 1 ]




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is a WeakMap Object in JavaScript ? What is a WeakMap Object in JavaScript ?
What is the use of Proxy Object in JavaScript ? What is the use of Proxy Object in JavaScript ?
What is a Blob Object in JavaScript ? What is a Blob Object in JavaScript ?
What is the role of a Service Worker in JavaScript ? What is the role of a Service Worker in JavaScript ?
How to Generate a Random Number in JavaScript ? How to Generate a Random Number in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14