Lodash - iteratee method


Advertisements

Syntax

_.iteratee([func=_.identity])

Creates a function that invokes func with the arguments of the created function. If func is a property name, the created function returns the property value for a given element. If func is an array or object, the created function returns true for elements that contain the equivalent source properties, otherwise it returns false.

Arguments

  • [func=_.identity] (*) − The value to convert to a callback.

Output

  • (Function) − Returns the callback.

Example

var _ = require('lodash');
var users = [
   { 'user': 'Joe', 'age': 36, 'active': true },
   { 'user': 'Robert', 'age': 40, 'active': false }
];
 
var result = _.filter(users, _.iteratee({ 'user': 'Joe', 'active': true }));
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ { user: 'Joe', age: 36, active: true } ]
lodash_util.htm
Advertisements