A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-iteratee-method/ below:

Lodash _.iteratee() Method - GeeksforGeeks

Lodash _.iteratee() Method

Last Updated : 09 Nov, 2023

Lodash_.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:

Returns:

[Function] Returns the callback.

Example 1: In this example, the the code uses the Lodash library to filter an array of objects based on a specific property value using the _.filter() method and a custom _.iteratee() function.

javascript
// Requiring the lodash library  
const _ = require("lodash"); 

// Use of _.iteratee() method     
let 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: In this example, the code uses the Lodash library to transform an array of objects by extracting property values using a custom _.iteratee() function and the _.map() method.

javascript
// Requiring the lodash library  
const _ = require("lodash");  

// Use of _.iteratee() method     
let 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"]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4