method

Util
since 3.7.0

Arguments

  • Array|string The path of the method to invoke.
  • ...* The arguments to invoke the method with.

Returns

Function the new invoker function.

Creates a function that invokes the method at path of a given object. Any additional arguments are provided to the invoked method.

Example of Lodash _.method

var objects = [
  { 'a': { 'b': _.constant(2) } },
  { 'a': { 'b': _.constant(1) } }
];

_.map(objects, _.method('a.b'));
// => [2, 1]

_.map(objects, _.method(['a', 'b']));
// => [2, 1]