大家一开始看到这个标题可能有点懵,咱先看一个需求,下面是模拟的数据。
const data = [
{ id: "001", type: "big", count: 10 },
{ id: "002", type: "small", count: 10 },
{ id: "003", type: "middle", count: 10 },
{ id: "004", type: "big", count: 10 },
{ id: "005", type: "small", count: 10 },
{ id: "006", type: "big", count: 10 },
{ id: "007", type: "small", count: 10 },
{ id: "008", type: "big", count: 10 },
{ id: "009", type: "middle", count: 10 },
{ id: "010", type: "big", count: 10 },
{ id: "011", type: "big", count: 10 },
{ id: "012", type: "small", count: 10 },
]
//将数据处理成这样
// 类型 数量
// small 40
// big 60
// middle 20
上面是后端返回的数据格式,今天有个小伙伴儿问我如何把这个数据处理成要求那样的,我这乍一看也没多