In my JavaScript code, I have an array of objects structured like this:
objArray = [
{"date":"07/19/2017 12:00:00 AM","count":"1000","code":"K100"},
{"date":"07/21/2017 12:00:00 AM","count":"899","code":"C835"},
{"date":"07/23/2017 12:00:00 AM","count":"700","code":"C837"},
{"date":"07/23/2017 12:00:00 AM","count":"800","code":"K100"},
{"date":"07/23/2017 12:00:00 AM","count":"50","code":"C837"}
];
I need to extract specific data from this array by:
- Removing duplicate date values
- Merging the code values into an array
- Adding up the count value for each unique date
The expected output should look like this:
newObjArray = [
{"date":"07/19/2017 12:00:00 AM","count":"1000","code":"K100"},
{"date":"07/21/2017 12:00:00 AM","count":"899","code":"C835"},
{"date":"07/23/2017 12:00:00 AM","count":"1550","code":["C837","K100","C837"]}
]
I've attempted a solution but couldn't achieve the desired result. Can anyone guide me on how to process this data correctly to get the expected output?