Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lodash _.iteratee() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.The _.iteratee method  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.

Syntax:

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

Parameters: This method accepts one parameter as mentioned above and described below:

  • [func=_.identity]: The value to convert to a callback.

Returns: [Function] Returns the callback.

Example 1:




// Requiring the lodash library  
const _ = require("lodash"); 
  
// Use of _.iteratee() method     
var info = [
  { 'company': 'Geeksforgeeks', 'Location': 'Noida', 'active': true },
  { 'company': 'Google',   'Location': 'California', 'active': true }
];
  
let gfg = _.filter(info, _.iteratee({ 'Location': 'Noida' }));
  
// Printing the output  
console.log(gfg)


Note: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

Output:

[Object {Location: "Noida", active: true, company: "Geeksforgeeks"}]

Example 2:




// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.iteratee() method     
var user = [
  { 'name': 'XXXX', 'age': 36, 'active': true },
  { 'name': 'YYYY',   'age': 40, 'active': false },
  { 'name': 'ZZZZ',   'age': 40, 'active': true }
];
  
let gfg = _.map(user, _.iteratee('name'));
  
// Printing the output  
console.log(gfg)


Note: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

Output:

["XXXX", "YYYY", "ZZZZ"]

My Personal Notes arrow_drop_up
Last Updated : 14 Sep, 2020
Like Article
Save Article
Similar Reads