var data=[{value:1200,count:5},{value:1200,count:10},{value:1230,count:5},{value:1240,count:5}]; console.log(_.chain(data) .groupBy("value") .map(function(value, key) { return [key, _.reduce(value, function(result, currentObject) { return { value: currentObject.value, count: result.count+ currentObject.count } }, { value: 0, count: 0 })]; }) .object() .value());
lodash js数组分组汇总
时间: 2024-10-26 03:59:59