Open In App

Lodash _.property() Method

Last Updated : 30 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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




// Requiring the lodash library 
const _ = require("lodash");
 
let info = {
    Company: 'GeeksforGeeks',
    Address: 'Noida'
};
 
// Use of _.property() method        
let gfg = _.property('Company')
    (info) === 'GeeksforGeeks'
 
// Printing the output 
console.log(gfg);


Output:

true

Example 2: In this example, we are printing the info by the use of the lodash _.property() method.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
let info = {
    Company: { name: 'GeeksforGeeks' },
    Contact: {
        Address:
        {
            AddressInfo: 'Noida'
        }
    }
};
 
// Use of _.property() method 
let propInfo = _.property(['Contact',
    'Address', 'AddressInfo',]);
 
// Printing the output 
console.log(propInfo(info));


Output:

Noida


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads