Saturday, November 22, 2025
HomeLanguagesJavascriptUnderscore.js _.dictionary() Method

Underscore.js _.dictionary() Method

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 : "neveropen" }
var gfgg = _.dictionary( ob );
  
console.log(gfgg("gfg"));


Output:

neveropen

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 : "neveropen" }
var gfgg = _.dictionary( ob );
  
console.log(gfgg("geek"));


Output:

undefined
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS