VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-topairs-method/

⇱ Lodash _.toPairs() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

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.

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.

Output:

[['x', 1], ['y', 2]]
Comment