Lodash - unzipWith 方法



語法

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

此方法類似於 _.unzip,只是它接受迭代器來指定如何合併重新組合的值。迭代器使用每個組的元素進行呼叫:(...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.htm
廣告
© . All rights reserved.