javascript

Remove items begin from start until given condition is false Lodash

To remove array items begin from start until the given condition is false, you can use dropWhile method of lodash.

var users = [
    { 'user': 'Ankit', 'active': false },
    { 'user': 'John', 'active': true },
    { 'user': 'Deo', 'active': false }
];

const result = _.dropWhile(users, function (o) {
    return !o.active;
});
Output
[
{
"user": "John",
"active": true
},
{
"user": "Deo",
"active": false
}
]

_.dropWhile Lodash

It creates a slice of an array that excludes some elements from the beginning. Elements are removed or deleted from the start until the predicate returns falsey values.

Example Demo

Was this helpful?