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
// Defining Lodash variableconst _ = require('lodash');Â
// Specifying a functionfunction 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 variableconst _ = require('lodash');Â
// Initializing a setconst 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.
Â
