HomeLanguagesJavascriptLodash _.toPairsIn() Method

Lodash _.toPairsIn() Method

The _.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: This method accepts a single parameter as mentioned above and described below:

  • object: This parameter holds the object to query.

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

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
function Fb() {
  this.id = 2045;
  this.username = 'fb_myself';
  this.password = 'fb1234';
}
   
Fb.prototype.email = '[email protected]';
  
// Use of _.toPairsIn() method 
console.log(_.toPairsIn(new Fb));


Output:

[
  [ 'id', 2045 ],
  [ 'username', 'fb_myself' ],
  [ 'password', 'fb1234' ],
  [ 'email', '[email protected]' ]
]

Example 2:  

Javascript




// 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:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
var GfG = {
    "Geek": "GFG"
}
  
// Use of _.toPairsIn() method 
console.log(_.toPairsIn(GfG));


Output:

[ [ 'Geek', 'GFG' ] ]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32548 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6922 POSTS0 COMMENTS
Nicole Veronica
12037 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12143 POSTS0 COMMENTS
Shaida Kate Naidoo
7057 POSTS0 COMMENTS
Ted Musemwa
7297 POSTS0 COMMENTS
Thapelo Manthata
7015 POSTS0 COMMENTS
Umr Jansen
7001 POSTS0 COMMENTS