Lodash - method


Advertisements

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