Lodash - some method


Advertisements

Syntax

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

Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. The predicate is invoked with three arguments: (value, index|key, collection).

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
lodash_collection.htm
Advertisements