Lodash - zipWith 方法

语法

_.zipWith([arrays], [iteratee=_.identity])

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

参数

  • [arrays] (...Array) − 要处理的数组。

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

输出

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

示例

var _ = require('lodash');
 
var result = _.zipWith([1, 2], [10, 20], function(a, b) {
   return a + b;
});
console.log(result);

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

命令

\>node tester.js

输出

[ 11, 22 ]

lodash_array.html