Lodash - unzipWith 方法

语法

_.unzipWith(array, [iteratee=_.identity])

此方法与 _.unzip 类似,不同之处在于它接受 iteratee 来指定应如何组合重新分组的值。使用每个组的元素调用 iteratee:(...group)。

参数

  • array (Array) − 要处理的分组元素数组。

  • [iteratee=_.identity] (Function) −组合重新分组值的函数。

输出

  • (Array) − 返回重新分组元素的新数组。

示例

var _ = require('lodash');
var result = _.zip([1, 2], [10, 20]);
console.log(result);

result = _.unzipWith(result, _.add);
console.log(result);

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

[ [ 1, 10 ], [ 2, 20 ] ]
[ 3, 30 ]

lodash_array.html