Removing array items from END until given condition is false using Lodash

In today’s article, we will learn about how to remove array elements from the last until a specified condition is not satisfied in an array. To do so we can use _.dropRightWhile() function of lodash in JavaScript.

About Lodash’s .dropRightWhile() Method

Similar to the Lodash’s dropWhile() function, this function is also used to return the value of the given array after slicing. dropRightWhile() method will remove the array elements from the last until the given condition is satisfied.


_.dropRightWhile(array, [predicate=_.identity])

First parameter is array which needs to be sliced and the second argument will be the function that will either returns true or false depending on the condition given to make it stop slicing the array further.


// Requiring the Lodash library
const _ = require("lodash");

var users = [
    { 'user': 'Arpit', 'active': true },
    { 'user': 'Vijay', 'active': false },
    { 'user': 'Ishika', 'active': false }

const result = _.dropRightWhile(users, function (o) { 
    return !;


{ 'user': 'Arpit', 'active': true }

Leave a Comment