i having trouble to transform the following array data1 to look like data2:I tried to use lodash but its a bit strange _gropuby gives me an object array. Should i be looping inside the array...creating a custom function for this. or is there a trick in lodash to simplify this. Thankssss /********************************************************************************************
let data1 = [{
KlasCode: "AA",
LESDatum: "06/02/2017",
LESID: "1",
ModuleID: "1061",
ParticipationLetterCode: "Y"
}, {
KlasCode: "AA",
LESDatum: "07/02/2017",
LESID: "2",
ModuleID: "1061",
ParticipationLetterCode: "X",
},
{
KlasCode: "AA",
LESDatum: "13/02/2017",
LESID: "3",
ModuleID: "1062",
ParticipationLetterCode: "Z"
},
{
KlasCode: "BB",
LESDatum: "16/02/2017",
LESID: "4",
ModuleID: "1063",
ParticipationLetterCode: "X"
}
]
//The output should be like a tree array system, something more organized such as the following code :
let data2 = [{
KlasCode: "AA",
Modules: [
{
ModuleID: "1061",
Participation: [{
ParticipationLetterCode: "Y",
LESDatum: "06/02/2017",
LESID: "1"
},
{
ParticipationLetterCode: "X",
LESDatum: "07/02/2017",
LESID: "2"
}
},
{
ModuleID: "1062",
Participation:[{
ParticipationLetterCode: "Z",
LESDatum: "13/02/2017",
LESID: "3"
}]
}
}]
},
{
KlasCode: "BB",
Modules: [{
ModuleID: "1063",
Participation: [{
ParticipationLetterCode: "x",
LESDatum: "6/02/2017",
LESID: "4"
}]
}]
}
]