Lodash _.toPairs() Method
Last Updated :
27 Oct, 2023
Lodash _.toPairs() method is used to create an array of enumerable string key-value pairs for an object that can be consumed by the _.fromPairs() function. If the object is a map or set, its entries are returned.
Syntax:
_.toPairs(object);
Parameter:
- object: This parameter holds the object to query.
Return Value:
This method returns the array of key-value pairs.
Example 1: In this example, we are getting a pair of the given function by creating a prototype of it by the use of the lodash _.fill() method.
Javascript
const _ = require( "lodash" );
function Fb() {
this .id = 2045;
this .username = 'fb_myself' ;
this .password = 'fb1234' ;
}
Fb.prototype.email = 'myself@gmail.com' ;
console.log(_.toPairs( new Fb));
|
Output:
[["id", 2045], ["username", "fb_myself"], ["password", "fb1234"]]
Example 2: In this example, we are getting a pair of the given object by the use of the lodash _.fill() method.
Javascript
const _ = require( "lodash" );
let GfG = {
'x' : 1,
'y' : 2
}
console.log(_.toPairs(GfG));
|
Output:
[['x', 1], ['y', 2]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...