javascript
Remove items starting from last untill given condition is false Lodash
To remove array items starting from last until the given condition is false, you can use dropRightWhile method of lodash javascript library
var users = [
{ 'user': 'Ankit', 'active': true },
{ 'user': 'John', 'active': false },
{ 'user': 'Deo', 'active': false }
];
const result = _.dropRightWhile(users, function (o) {
return !o.active;
});
// { 'user': 'Ankit', 'active': true }
Output
{ 'user': 'Ankit', 'active': true }
_.dropRightWhile Lodash
It cretes a slice of array which excludes some elements from the end. Elements are removed or deleted from the end until the predicate return falsey values.
Example Demo
Was this helpful?
Similar Posts
- Remove items begin from start until given condition is false Lodash
- Remove all false, null, undefined and empty values from array using Lodash
- Remove last n elements from an array using Lodash
- Lodash - Get all elements of array except the last one
- Lodash - Get the last element of an array
- Lodash - Get index of array item based on some condition
- Remove empty, false, undefined values from array Javscript