Lodash _.entries() Method

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:

_.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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

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

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.