Lodash _.property() Method
Last Updated :
30 Oct, 2023
Lodash _.property() method is used to return a function that will return the specified property of any passed-in object.
Syntax:
_.property(path);
Parameters:
- path: This parameter holds the path of the property to get.
Return Value:
This method returns a new accessor function.
Example 1: In this example, we are checking that the Company name is the same as a given name by the use of the lodash _.property() method.
Javascript
const _ = require( "lodash" );
let info = {
Company: 'GeeksforGeeks' ,
Address: 'Noida'
};
let gfg = _.property( 'Company' )
(info) === 'GeeksforGeeks'
console.log(gfg);
|
Output:
true
Example 2: In this example, we are printing the info by the use of the lodash _.property() method.
Javascript
const _ = require( "lodash" );
let info = {
Company: { name: 'GeeksforGeeks' },
Contact: {
Address:
{
AddressInfo: 'Noida'
}
}
};
let propInfo = _.property([ 'Contact' ,
'Address' , 'AddressInfo' ,]);
console.log(propInfo(info));
|
Output:
Noida
Share your thoughts in the comments
Please Login to comment...