Lodash - zipWith 方法



語法

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

此方法類似於 _zip,只是它接受迭代器來指定應如何組合分組值。對每個組的元素呼叫迭代器:(...group)。

引數

  • [arrays] (...Array) − 要處理的陣列。

  • [iteratee=_.identity] (Function) − 用於合併分組值函式。

輸出

  • (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.htm
廣告
© . All rights reserved.