Open In App

Underscore.js _.dictionary() Method

Last Updated : 09 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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

Syntax:

funct = _.dictionary( object );

Parameters: 

  • object: This method takes the object from which the field is to be searched.

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 underscore.js contrib library to be installed. Underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:

JavaScript
// Defining underscore contrib variable
var _ = require('underscore-contrib'); 

var ob = { gfg : "GeeksforGeeks" }
var gfgg = _.dictionary( ob );

console.log(gfgg("gfg"));

Output:

GeeksforGeeks

Example 2: If this function does not find any field then it will return undefined.

JavaScript
// Defining underscore contrib variable
var _ = require('underscore-contrib'); 

var ob = { gfg : "GeeksforGeeks" }
var gfgg = _.dictionary( ob );

console.log(gfgg("geek"));

Output:

undefined

Next Article

Similar Reads