Skip to content
Related Articles

Related Articles

Lodash _.keys() Method
  • Last Updated : 09 Sep, 2020

The _.keys() method is used to return the list of all keys of the given object.

Syntax:

_.keys(object)

Parameters: This method accepts a single parameter as mentioned above and described below:

  • object: This parameter holds the object elements.

Return Value: This method returns the array of all key of the given object.

Example 1:



Javascript




// Requiring the lodash library  
const _ = require("lodash");  
   
// Given object
var obj =  { 'a': 1, 'b': 2, 'c': 2 };
          
// Use of _.keys method 
console.log(_.keys(obj));

Output:

['a', 'b', 'c']

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
   
// Given object
var obj = { 
            Name: "GeeksforGeeks"
            password: "gfg@1234"
            username: "your_geeks"
        
          
// Use of _.keys method 
console.log(_.keys(obj));

Output:

["Name", "password", "username"]
My Personal Notes arrow_drop_up
Recommended Articles
Page :