Open In App

Underscore.js _.pairs() Function

Underscore.js _.pairs() function is used to convert an object into an array of arrays that contain the [key, value] pairs of the object as elements.

Syntax:

_.pairs( object );

Parameters:

Return Value:

It returns the array of [key, value] pairs.



Example 1: The below code example implements the _.pairs() function of underscore.js practically.




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

Output:



Example 2: The below code example illustrates the another use of _.pairs() function of underscore.js.




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

Output:


Article Tags :