Open In App

Lodash _.property() Method

Lodash _.property() method is used to return a function that will return the specified property of any passed-in object.

Syntax: 

_.property(path);

Parameters:

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.




// 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.




// 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

Article Tags :