Lodash教程

Lodash invokeMap method

语法:

_.invokeMap(collection, path, [args])
Invokes the method at path of each element in collection, returning an array of the results of each invoked method. Any additional arguments are provided to each invoked method. If path is a function, it's invoked for, and this bound to, each element in collection.

参数:

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.

输出:

(Array) − Returns the array of results.

例子:

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.

命令:

\>node tester.js

输出:

[ [ 1, 5, 7 ], [ 1, 2, 3 ] ]
[ [ '1', '2', '3' ], [ '4', '5', '6' ] ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4