Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The Lodash _.methodOf() method creates a function that invokes the method at a given path of the object. Any additional arguments are provided to the invoked method.
Syntax:
_.methodOf(object, args)
Parameters: This method accepts two parameters as mentioned above and described below:
- object: This is the object to query.
- args: These are the arguments to invoke the method with.
Return Value: This method returns the new invoker function.
Example 1:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.methodOf() method var array = _.times(4, _.constant), object = { 'www' : array, 'neveropen' : array, 'for' : array , 'geek' :array }; gfg = _.map([ 'neveropen[1]' , 'geek[2]' ], _.methodOf(object)); // Printing the output console.log(gfg); |
Output:
[1, 2]
Example 2:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.methodOf() method var array = _.times(4, _.constant), object = { 'www' : array, 'neveropen' : array, 'for' : array , 'geek' :array }; gfg = _.map([[ 'www' , '1' ], [ 'for' , '0' ]], _.methodOf(object)); // Printing the output console.log(gfg); |
Output :
[1, 0]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!