invokeMap source npm

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

调用 path 的方法处理集合中的每一个元素,返回处理的数组。 如何附加的参数会传入到调用方法中。如果方法名是个函数,集合中的每个元素都会被调用到。

参数

  1. collection (Array|Object)

    需要遍历的集合

  2. path (Array|Function|string)

    要调用的方法名 或者 这个函数会处理每一个元素

  3. [args] (...*)

    The arguments to invoke each method with.

返回值 (Array)

返回数组结果

示例

_.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
// => [[1, 5, 7], [1, 2, 3]]

_.invokeMap([123, 456], String.prototype.split, '');
// => [['1', '2', '3'], ['4', '5', '6']]