Given the following array of objects:
[
{
\"notes\": \"Game was played\",
\"time\": \"2017-10-04T20:24:30+00:00\",
\"sport\": \"hockey\",
\"owner\": \"steve\
let a =[{
"notes": "Game was played",
"time": "2017-10-04T20:24:30+00:00",
"sport": "hockey",
"owner": "steve",
"players": "10",
"game_id": 1,
},
{
"notes": "Game was played",
"time": "2017-10-04T12:35:30+00:00",
"sport": "lacrosse",
"owner": "steve",
"players": "6",
"game_id": 2,
},
{
"notes": "Game was played",
"time": "2017-10-14T20:32:30+00:00",
"sport": "hockey",
"owner": "steve",
"players": "4",
"game_id": 3,
},
{
"notes": "Game was played",
"time": "2017-10-04T10:12:30+00:00",
"sport": "hockey",
"owner": "henry",
"players": "10",
"game_id": 4,
},
{
"notes": "Game was played",
"time": "2017-10-14T20:34:30+00:00",
"sport": "soccer",
"owner": "john",
"players": "12",
"game_id": 5,
}]
let finalObj = {}
a.forEach((games) => {
const date = games.time.split('T')[0]
if (finalObj[date]) {
finalObj[date].push(games);
} else {
finalObj[date] = [games];
}
})
console.log(finalObj)