Lodash _.keys() Method
Last Updated :
20 Oct, 2023
Lodash _.keys() method is used to return the list of all keys of the given object.
Syntax:
_.keys(object);
Parameters:
- object: This parameter holds the object elements.
Return Value:
This method returns the array of all keys of the given object.
Example 1: In this example, we are printing the keys of an object using the _.keys() method.
Javascript
const _ = require( "lodash" );
let obj = { 'a' : 1, 'b' : 2, 'c' : 2 };
console.log(_.keys(obj));
|
Output:
['a', 'b', 'c']
Example 2: In this example, we are printing the keys of an object using the _.keys() method.
Javascript
const _ = require( "lodash" );
let obj = {
Name: "GeeksforGeeks" ,
password: "gfg@1234" ,
username: "your_geeks"
}
console.log(_.keys(obj));
|
Output:
["Name", "password", "username"]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...