案例如下
let list = [
{
defineCode: "001",
defineName: "分级名称1",
gradeType: "分级类型1",
orgVos: [
{
orgCode: "组织编码1",
orgName: "组织名称1",
},
],
},
{
defineCode: "001",
defineName: "分级名称1",
gradeType: "分级类型1",
orgVos: [
{
orgCode: "组织编码2",
orgName: "组织名称2",
},
],
},
{
defineCode: "002",
defineName: "分级名称2",
gradeType: "分级类型2",
orgVos: [
{
orgCode: "组织编码2",
orgName: "组织名称2",
},
],
},
];
const mergedList = list.reduce((acc, curr) => {
const existingItem = acc.find(item => item.defineName === curr.defineName);
if (existingItem) {
existingItem.orgVos = [...existingItem.orgVos, ...curr.orgVos];
} else {
acc.push(curr);
}
return acc;
}, []);
console.log(mergedList)
打印内容如下
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。