Lodash _.dropRight() function is used to delete the elements from the right of the array i.e from the (n-1)th element.
Syntax:
_.dropRight(array, n);
Parameters:
- array: It is the original array from which elements are to be deleted.
- n: Here n is the number of elements that are to be deleted from the array. By default, it is set to one.
Return Value:
It returns the array.
Note:
Install the lodash module by using command npm install lodash before using the code given below.
Example 1: In this example, we are printing the new array having two elements less from the right side of the original array.
javascript
const _ = require('lodash');
let array1 = [1, 2, 3, 4, 5]
let newArray = _.dropRight(array1, 2);
console.log('original Array: ', array1)
console.log('new Array: ', newArray)
|
Output:

Example 2: In this example, given value is greater than the length of the given array so it is giving empty array.
javascript
const _ = require('lodash');
let array1 = [1, 2, 3, 4, 5]
let newArray = _.dropRight(array1, 10);
console.log('original Array: ', array1)
console.log('new Array: ', newArray)
|
Output:

Example 3: In this example, we are printing the new array having one element less from the right side of the original array.
javascript
const _ = require('lodash');
let array1 = [
{ 'a': 1, 'b': 2 },
{ 'a': 2, 'b': 1 },
{ 'b': 2 }
]
let newArray = _.dropRight(array1);
console.log('original Array: ', array1)
console.log('new Array: ', newArray)
|
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!
Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!
Last Updated :
03 Nov, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...