A RetroSearch Logo

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

Search Query:

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

Lodash _.mapValues() Method - GeeksforGeeks

Lodash _.mapValues() Method

Last Updated : 31 Oct, 2023

Lodash _.mapValues() method is used to create a new mapped object with the same keys as the given object and the values are generated using the given iteratee function.

Syntax:
_.mapValues(object, iteratee);
Parameters: Return Value:

This method returns the new mapped object.

Example 1: In this example, we are creating a new object having the same password as the old one by the use of the lodash _.mapValues() method.

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

let users = {
    'Geeksforgeeks': {
        'username': 'gfg_id',
        'password': 'gfg@123'
    },
    'W3school': {
        'username': 'w3school_id',
        'password': 'w@123'
    }
};

// Using the _.mapValues() method 
console.log(
    _.mapValues(users, function (o) {
        return o.password;
    })
);

 Output: 

{Geeksforgeeks: "gfg@123", W3school: "w@123"} 

Example 2: In this example, we are creating a new object having the same username as the old one by the use of the lodash _.mapValues() method.

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

let users = {
  'Geeksforgeeks': {
    'username': 'gfg_id',
    'password': 'gfg@123'
  },
  'W3school': {
    'username': 'w3school_id',
    'password': 'w@123'
  }
};

// Using the _.mapValues() method 
console.log(_.mapValues(users, 'username'));

Output:

{ Geeksforgeeks: 'gfg_id', W3school: 'w3school_id' }


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