Lodash – drop While methods

  • Post author:
  • Post category:Lodash
  • Post comments:1 Comment
Lodash - drop While methods

Syntax Of Lodash drop While methods

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

Lodash drop While methods Create a slice of array excluding elements dropped from the beginning. 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 = _.dropWhile(users, function(user) { return !user.active; });
console.log(result);

result = _.dropWhile(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: 'Ted', active: true }, { user: 'Julie', active: false } ]
[ { user: 'Ted', active: true }, { user: 'Julie', active: false } ]

Next Topic – Click Here

This Post Has One Comment

Leave a Reply