I have a data of students and their marks in various subjects as an array of objects. I need to club the data as a single object when the name of the two objects are same so that I will have only one record for each student. An example of the sample data:
{
data: [{
"name: xxx,
"createdDate:10/01/2018,
subj1: 20,
subj2: 40
},
{
"name: xxx,
"createdDate:10/11/2017,
subj1: 40,
subj2: 70
},
{
"name: yyy,
"createdDate:10/01/2018,
subj1: 20,
subj2: 40
}]
}
and I need to convert it something like this:
{
data: [
{
name: xxx,
subj1: [20, 40],
subj2: [70, 40]
},
{
name: yyy,
subj1: [20],
subj2: [40]
}
]
}
How can I achieve this in node js
. Only through looping I can do or is there an easy way I can achieve this by using libraries like lodash,underscore js.