- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - method
Syntax
_.method(path, [args])
Creates a function that invokes the method at path of a given object. Any additional arguments are provided to the invoked method.
Arguments
path (Array|string) − The path of the method to invoke.
[args] (...*) − The arguments to invoke the method with.
Output
(Function) − Returns the new invoker function.
Example
var _ = require('lodash'); var objects = [ { 'a': { 'b': _.constant(4) } }, { 'a': { 'b': _.constant(5) } } ]; console.log(_.map(objects, _.method('a.b'))); console.log(_.map(objects, _.method(['a', 'b'])));
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ 4, 5 ] [ 4, 5 ]
lodash_util.htm
Advertisements
To Continue Learning Please Login
Login with Google