Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Underscore.js _.pairs() Function

  • Last Updated : 25 Nov, 2021

The _.pairs() function is used to convert an object into [key, value] pairs.

Syntax:

_.pairs( object )

Parameters: This function accepts one parameter as mentioned above and described below:

  • object: It contains the object element that holds the elements of key and value pair.

Return Value: It returns the list of [key, value] pair.

Example 1:






<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
            src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var obj = {
            Company: "GeeksforGeeks",
            Address: "Noida",
            Contact: "+91 9876543210",
            Email: "abc@gfg.com"
        }
        console.log(_.pairs(obj));
    </script>
</body>
  
</html>

Output:

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
            src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var objectPair = _.pairs({ num1: 10, num2: 15, num3: 20, num4: 25, num5: 30 });
  
        console.log(objectPair);
    </script>
</body>
  
</html>

Output:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!