Saturday, October 25, 2025
HomeLanguagesJavascriptLodash _.toPairs() Method

Lodash _.toPairs() Method

The _.toPairs() method is used to create an array of own enumerable string key-value pairs for an object which can be consumed by the _.fromPairs() function. If the object is a map or set, its entries are returned.

Syntax:

_.toPairs(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';
}
   
// This will not be included in the array
Fb.prototype.email = 'myself@gmail.com';
  
// Use of _.toPairs() method 
console.log(_.toPairs(new Fb));


Output:

[["id", 2045], ["username", "fb_myself"], ["password", "fb1234"]]

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
var GfG = {
      'x': 1,
      'y': 2
 }
  
// Use of _.toPairs() method 
console.log(_.toPairs(GfG));


Output:

[['x', 1], ['y', 2]]
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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS