_.method

_.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.

Since

3.7.0

Arguments

  1. path (Array|string): The path of the method to invoke.
  2. [args] (...*): The arguments to invoke the method with.

Returns

(Function): Returns the new invoker function.

Example

1
2
3
4
5
6
7
8
9
10
11
var objects = [
  'a': { 'b': _.constant(2) } },
 
  'a': { 'b': _.constant(1) } }
];
  
_.map(objects, _.method('a.b'));
// => [2, 1]
  
_.map(objects, _.method(['a''b']));
// => [2, 1]
doc_Lodash
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.