下面有如下数组:
const fData = [
{ownerName: "大厦a", type: "服务类型1", total: 85}
{ownerName: "大厦a", type: "服务类型2", total: 22}
{ownerName: "大厦b", type: "服务类型1", total: 11}
{ownerName: "大厦b", type: "服务类型2", total: 11}
{ownerName: "大厦c", type: "服务类型1", total: 121}
{ownerName: "大厦c", type: "服务类型2", total: 11}
]
希望重构成如下数组:
[{ownerName: "大厦a", "服务类型1": 85, "服务类型2": 22}
{ownerName: "大厦b", "服务类型1": 11, "服务类型2": 11}
{ownerName: "大厦c", "服务类型1": 121, "服务类型2": 11}
我目前进行如下代码:
let newName = map(uniq(ownerName), (item) => {
return {
ownerName: item,
};
});
let newType = map(uniq(type), (item) => {
return {
type: item,
};
});
其中uniq和map是引用的第三方lodash的库。
往下就不知道该如何写了。求指导,谢谢
呼啦一阵风
相关分类