Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Lodash _.entries() Method

  • Last Updated : 13 Apr, 2021

The _.entries() method is used to create an array of keyed-value pairs for the specified object. If object is a map or set, its entries are returned.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

_.entries(object)

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

  • object: This parameter holds the object to query.

Return Value: This method returns the key-value pairs.



Example 1:

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
// Specifying a function
function gfg() {
  this.A = 5;
  this.B = 10;
  this.C = 15;
}
 
// Calling the _.entries() function
_.entries(new gfg);

 

 

Output:

 

[ [ 'A', 5 ], [ 'B', 10 ], [ 'C', 15 ] ]

 

Example 2: In the below code, a set is taken as the object, hence the function _.entries() returns its entries.



 

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
// Initializing a set
const object = {a: {b: 1}};
 
// Calling the _.entries() function
_.entries(object);

 

 

Output:

 

[ [ 'a', { b: 1 } ] ]

 

Note: This will not work in normal JavaScript because it requires the lodash library to be installed.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!