Lodash – invokeMap method

Lodash - invokeMap method

Syntax Of Lodash invokeMap method

_.invokeMap(collection, path, [args])

Lodash invokeMap method at the path of each element in the collection, returning an array of the results of each invoked method. Any additional arguments are provided to each invoked method. If the path is a function, it’s invoked for, and this is bound to, each element in the collection.

Arguments

  • collection (Array|Object) โˆ’ The collection to iterate over.
  • path (Array|Function|string) โˆ’ The path of the method to invoke or the function invoked per iteration.
  • [args] (…*) โˆ’ The arguments to invoke each method with.

Output

  • (Array) โˆ’ Returns the array of results.

Example

var _ = require('lodash');
var list = [[5, 1, 7], [3, 2, 1]];
 
var result = _.invokeMap(list, 'sort');
console.log(result);

result = _.invokeMap([123, 456], String.prototype.split, '');
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ [ 1, 5, 7 ], [ 1, 2, 3 ] ]
[ [ '1', '2', '3' ], [ '4', '5', '6' ] ]

Next Topic – Click Here

Leave a Reply