Open In App

Lodash _.dictionary() Method

The Lodash _.dictionary() method returns a function that will attempt to look up a field that it is given.

Syntax:



funct = _.dictionary( object );

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

Return Value: This method returns a function that will attempt to look up a field that is given.



Note: This will not work in normal JavaScript because it requires the lodash.js contrib library to be installed. Lodash.js contrib library can be installed using npm install lodash-contrib.

Example 1:




// Defining underscore lodash variable 
var _ = require('lodash-contrib'); 
  
var ob = { gfg : "GeeksforGeeks"
var gfgg = _.dictionary( ob ); 
    
console.log(gfgg("gfg"));

Output:

GeeksforGeeks

Example 2:




// Defining underscore lodash variable 
var _ = require('lodash-contrib'); 
  
var ob = { gfg : "GeeksforGeeks"
var gfgg = _.dictionary( ob ); 
    
console.log(gfgg("geek"));

Output:

undefined
Article Tags :