我在Node应用程序中生成以下json:
[ { id: 1,
name: 'user1',
sport: 'athletics',
medal_count: '1'
},
{ id: 1,
name: 'user1',
sport: 'tennis',
medal_count: '2'
},
{ id: 2,
name: 'user2',
sport: ['football'],
medal_count: '2'
}
]
现在,我想将用户连接起来,使他们看起来像一个单独的对象,其中的sport
列在一个数组中,medal_count
为该用户集合。上面的json看起来像这样:
[ { id: 1,
name: 'user1',
sport: [
'athletics',
'tennis'
],
medal_count: '3'
},
{ id: 2,
name: 'user2',
sport: 'football',
medal_count: '2'
}
]
这是怎么做的?我认为这应该通过map reduce函数来完成,对吗?
https://stackoverflow.com/questions/56044483
复制相似问题