Lodash – some method

Lodash - some method

Syntax

_.some(collection, [predicate=_.identity])

Lodash some method checks if the predicate returns truthy for any element of the collection. Iteration is stopped once predicate returns truthy.

Arguments

  • collection (Array|Object) − The collection to iterate over.
  • [predicate=_.identity] (Function) − The function invoked per iteration.

Output

  • (boolean) − Returns true if any element passes the predicate check, else false.

Example

var _ = require('lodash');
var users = [
   { user: 'Joe', age: 48, active: false },
   { user: 'Robert', age: 34, active: true },
   { user: 'Julie', age: 40, active: false },
   { user: 'Stafey', age: 36, active: true }
];
var result = _.some(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

true

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply