Lodash _.reverse() is used to reverse the array. This function changes the original array and also returns a new array.
Syntax:
_.reverse( array )
Parameters:
This function accepts single parameter array that holds the array of elements.
Return Value:
It returns the reversed array.
Note: Please install lodash module by using npm install lodash
before using the below given code.
Example 1: This examples shows that this function effect the original array.
javascript
const _ = require( "lodash" );
let array1 = [1, 2, 3, 4]
console.log( "original Array1: " , array1)
let reversedArray = _.reverse(array1);
console.log( "reversed Array: " , reversedArray)
console.log( "original Array1: " , array1)
|
Output:

Example 2: In this example, we will take an array of objects and reverse them.
javascript
const _ = require( "lodash" );
let array1 = [
{ "a" : 1 },
{ "a" : 2, "b" : 3 },
{ "c" : 3 }
]
console.log( "original Array1: " , array1)
let reversedArray = _.reverse(array1);
console.log( "reversed Array: " , reversedArray)
console.log( "original Array1: " , array1)
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
13 Nov, 2023
Like Article
Save Article