Syntax Of Lodash drop Right While method
_.dropRightWhile(array, [predicate=_.identity])
The Lodash drop Right While method Creates a slice of array excluding elements dropped from the end. Elements are dropped until the predicate returns false. The predicate is invoked with three arguments: (value, index, array).
Arguments
- array (Array) − The array to query.
- [predicate=_.identity] (Function) − The function invoked per iteration.
Output
- (Array) − Returns the slice of array.
Example
var _ = require('lodash'); var users = [ { user: 'Sam', active: false }, { user: 'Ted', active: true }, { user: 'Julie', active: false } ]; var result = _.dropRightWhile(users, function(user) { return !user.active; }); console.log(result); result = _.dropRightWhile(users, ['active', false]); console.log(result);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ { user: 'Sam', active: false }, { user: 'Ted', active: true } ] [ { user: 'Sam', active: false }, { user: 'Ted', active: true } ]
Next Topic – Click Here
Pingback: Lodash - Array - Adglob Infosystem Pvt Ltd