【发布时间】:2017-05-02 15:37:11
【问题描述】:
我有一个数组:
[
{
assignmentId:17,
email:"john.smith@email.com"
expectation: "Make sure to proofread!",
firstName:"John"
id:23
ignoreForFeedback: true
lastName:"Smith"
level:2
levelFraction:null
score:35
},
{
assignmentId:17
countsPerCategory: Array(4)
email:"john.smith@email.com"
firstName:"John"
frequentErrors: Array(5)
id:23
ignoreForGrading: true
lastName:"Smith"
},
{
assignmentId:17,
email:"cl@email.com"
expectation: "cite sources",
firstName:"Cindy"
id:45
ignoreForFeedback: true
lastName:"Lee"
level:2
levelFraction:null
score:32
},
{
assignmentId:17
countsPerCategory: Array(4)
email:"cl@email.com"
firstName:"Cindy"
frequentErrors: Array(5)
id:45
ignoreForGrading: true
lastName:"Lee"
}
]
我想将具有相同“id”的对象组合到数组中的同一个对象中。它们的公共键也应该组合起来(例如:'firstName'、'email')。有人可以建议最好的方法吗?使用 ES6 或 Lodash
【问题讨论】:
-
看看我的解决方案是不是你想要的
标签: javascript arrays lodash