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
}
]
{
"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?
Similar Posts
- Remove items starting from last untill given condition is false Lodash
- Remove all false, null, undefined and empty values from array using Lodash
- Remove new line separator from start and end positions of string in Javascript
- Lodash - Get index of array item based on some condition
- Remove empty, false, undefined values from array Javscript
- Javascript code to remove falsy value like null, undefined, false from array
- Make y axis to start from 0 in Chart.js