Saturday, October 25, 2025
HomeLanguagesJavascriptUnderscore.js _.pairs() Function

Underscore.js _.pairs() Function

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: "neveropen",
            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:

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