举个例子:
let data = [
{name:'aaa', id:'1', color:'blue'},
{name:'aaa', id:'2', color:'green'}
];
let temp = [];
data.forEach(x => {
let index = temp.findIndex(y => y.name == x.name);
if (index == -1) {
temp.push({
name: x.name,
list:[{
id: x.id,
color:x.color
}]
})
} else {
temp[index].list.push({
id: x.id,
color:x.color
})
}
})
结果:
[
name: 'aaa',
list: [
{id:'1', color:'blue'},
{id:'2', color:'green'}
]
]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。