let arr = [
{
code: "10AT",
batch: "1027",
store: "001",
number: 10,
},
{
code: "10AT",
batch: "1027",
store: "001",
number: 10,
},
{
code: "10AT",
batch: "1027",
store: "002",
number: 10,
},
{
code: "10AAT",
batch: "1027",
store: "002",
number: 100,
},
];
需要将code,batch,store都相同的number累加,并且去除重复项,结果为
let result = [
{
code: "10AT",
batch: "1027",
store: "001",
number: 20,
},
{
code: "10AT",
batch: "1027",
store: "002",
number: 10,
},
{
code: "10AAT",
batch: "1027",
store: "002",
number: 100,
},
];
基本思路:分组→按组合计→处理成结果视图
用 Lodash
自己写