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
// Requiring the lodash library const _ = require( "lodash" ); Â
// Given object let obj = { 'a' : 1, 'b' : 2, 'c' : 2 }; Â
// Use of _.keys method 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
// Requiring the lodash library const _ = require( "lodash" ); Â
// Given object let obj = { Â Â Â Â Name: "neveropen" , Â Â Â Â password: "gfg@1234" , Â Â Â Â username: "your_neveropen" } Â
// Use of _.keys method console.log(_.keys(obj)); |
Output:
["Name", "password", "username"]