Here is the existing Object Array structure:
[ { "date":"12-09-2019 12:00 PM", "id":"1", "name":"hello1" }, { "date":"12-09-2019 03:00 PM", "id":"2", "name":"hello2" }, { "date":"12-09-2019 07:00 PM", "id":"3", "name":"hello3" }, { "date":"13-09-2019 08:00 AM", "id":"4", "name":"hello4" }, { "date":"14-09-2019 10:00 AM", "id":"5", "name":"hello5" }, { "date":"14-09-2019 11:30 PM", "id":"6", "name":"hello6" } ]
However, I am looking for a new filtered array based on the date as shown below:
[ { "date": "12-09-2019", "data": [ { "id": "1", "name": "hello1" }, { "id": "2", "name": "hello2" }, { "id": "3", "name": "hello3" } ] }, { "date": "13-09-2019", "data": [ { "id": "4", "name": "hello4" } ] }, { "date": "14-09-2019", "data": [ { "id": "5", "name": "hello5" }, { "id": "6", "name": "hello6" } ] } ]
I would appreciate any assistance you can provide in achieving this.
Here is the code snippet of what I have attempted so far:
public data: any;
public dateGroupArr: any = [];
this.data.forEach((item, index) => {
dataArr = item;
dateGroupArr[item['date']]['date'] = item['date'];
dataArr.splice(dataArr['date']);
dateGroupArr[item['date']]['data'] = dataArr;
});
Thank you for your help.