Open In App

Underscore.js _.keys() Function

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Underscore.js_.keys() function is used to return the list of all keys of the given object.

Syntax:

_.keys( object );

Parameters:

  • object: It contains the object elements.

Return Value:

This function returns the list of all keys of the given object.

Example 1: This example shows the use of the _.keys() function.

html
<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
    </script>
</head>

<body>
    <script type="text/javascript">

        let obj = {
            Company: "GeeksforGeeks",
            Address: "Noida",
            Contact: "+91 9876543210",
            Email: "[email protected]"
        }
        console.log(_.keys(obj)); 
    </script>
</body>

</html>

Output:

Example 2: This example shows the use of the _.keys() function.

html
<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
    </script>
</head>

<body>
    <script type="text/javascript">

        let key = _.keys({
            Name: "Ashok",
            Address: "Noida",
            Mobile: "+91 9876543210",
            Email: "[email protected]"
        });

        console.log(key); 
    </script>
</body>

</html>

Output:


Next Article

Similar Reads