Lodash _.method() method creates a function that invokes the method at the path of a given object. Any additional arguments are provided to the invoked method.
Syntax:
_.method(path, args);
Parameters:
- path: This is the path to invoke.
- args: These are the arguments to invoke the method with.
Return Value:
This method returns the new invoker function.
Example 1: In this example, we are using the lodash _.method() method.
Javascript
const _ = require("lodash");
let gfg = [
{ 'a': { 'b': _.constant("geeks") } },
{ 'a': { 'b': _.constant("for") } },
{ 'a': { 'b': _.constant("geeks") } }
];
let ans = _.map(gfg, _.method('a.b'));
console.log(ans);
|
Output:
["geeks", "for", "geeks"]
Example 2: In this example, we are using the lodash _.method() method.
Javascript
const _ = require("lodash");
let gfg = [
{ 'b': _.constant(1) },
{ 'b': _.constant(5) },
{ 'b': _.constant(8) }
];
let ans = _.map(gfg, _.method(['b']));
console.log(ans);
|
Output :
[1, 5, 8]
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
03 Nov, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...