一个数组:
var a = [
{
id: 5,
name: 'a',
age: '16'
},
{
id: 5,
name: 'b',
age: '17'
},
{
id: 5,
name: 'c',
age: '16'
},
{
id: 6,
name: 'd',
age: '16'
}
];
现在想把他转换成这样:
var b = [
{
id: 5,
name: [
a,
b,
c
],
age: [
16,
17,
16
]
},
{
id: 6,
name: 'd',
age: '16'
}
];
就是说,把id相同的两个合并,不相同的不变,怎么弄···
只能循环遍历