Lodash _.toPairsIn() method is used to create an array of own and inherited enumerable string key-value pairs for an object which can be consumed by the _.fromPairs() function. If an object is a map or set, its entries are returned.
Syntax:
_.toPairsIn(object);Parameters:
- 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 the key and value pair of the given function by the use of the lodash _.toPairsIn() method.
// Requiring the lodash library
const _ = require("lodash");
function Fb() {
this.id = 2045;
this.username = 'fb_myself';
this.password = 'fb1234';
}
Fb.prototype.email = 'myself@gmail.com';
// Use of _.toPairsIn() method
console.log(_.toPairsIn(new Fb));
Output:
[
[ 'id', 2045 ],
[ 'username', 'fb_myself' ],
[ 'password', 'fb1234' ],
[ 'email', 'myself@gmail.com' ]
]
Example 2: In this example, we are getting the key and value pair of the given function by the use of the lodash _.toPairsIn() method.
// Requiring the lodash library
const _ = require("lodash");
function Gfg() {
this.x = 1;
this.y = 2;
}
Gfg.prototype.z = 3;
// Use of _.toPairsIn() method
console.log(_.toPairsIn(new Gfg));
Output:
[ ['x', 1], ['y', 2], ['z', 3] ]Example 3: In this example, we are getting the key and value pair of the given object by the use of the lodash _.toPairsIn() method.
// Requiring the lodash library
const _ = require("lodash");
let GfG = {
"Geek": "GFG"
}
// Use of _.toPairsIn() method
console.log(_.toPairsIn(GfG));
Output:
[ [ 'Geek', 'GFG' ] ]