{
"Name": "User1",
"SlotStartDate": "05/16/2018",
"SlotStartTime": "9:20AM"
},
{
"Name": "User1",
"SlotStartDate": "05/16/2018",
"SlotStartTime": "10:20AM"
},
{
"Name": "User1",
"SlotStartDate": "05/17/2018",
"SlotStartTime": "9:20AM"
},
{
"Name": "User1",
"SlotStartDate": "05/17/2018",
"SlotStartTime": "10:20AM"
},
{
"Name": "User2",
"SlotStartDate": "05/16/2018",
"SlotStartTime": "8:45AM"
},
{
"Name": "User2",
"SlotStartDate": "05/16/2018",
"SlotStartTime": "9:25AM"
}
{
"Name": "User2",
"SlotStartDate": "05/17/2018",
"SlotStartTime": "8:45AM"
},
{
"Name": "User2",
"SlotStartDate": "05/17/2018",
"SlotStartTime": "9:25AM"
}
Would appreciate assistance on using underscore.js to group the above data and return an array organized by user and date as follows:
Data grouped by user and date.
User1
- "05/16/2018"
- "9:20AM"
- "10:20AM"
- "05/17/2018"
- "9:20AM"
- "10:20AM"
User2
- "05/16/2018"
- "8:45AM"
- "9:25AM"
- "05/17/2018"
- "8:45AM"
- "9:25AM"
I have attempted the code snippet below:
var createGroups = _.groupBy(response2, function(value){
return value.Name + '#' + value.SlotStartDate
});
var groupedData = _.map(createGroups,function(createGroup){
return {
slottimes: _.pluck(createGroup,'SlotStartTime')
}
});
Your support is highly valued!