const arr = [1, 2, 3, 4, 5, 6, 7]; //remove last element (n=1) by default const arr1 = _.dropRight(arr); //remove last 3 elements const arr2 = _.dropRight(arr, 3); //remove last 5 elements const arr3 = _.dropRight(arr, 5);
The _.dropRight method of lodash is quite useful when it comes to delete or remove last n elements from the given array. It takes two arguments as parameter. The basic Syntax of this method is below
Array: This is a required parameter and it is the array which contains all the values along with those values which needs to be removed.
N: This is an optional paramter and it is integer type. The value you pass as N will delete last N items from the given array. The default value of this paraamter is 1 means if you do not pass this parameter value then it will delete last element from the array.