So I have a JSON file, that has some data for all the countries of the world. Each country is an array of objects. Each object in the array has a Date property, a confirmed property etc.
{
"Afghanistan": [
{
"date": "2020-1-22",
"confirmed": 5,
"deaths": 0,
"recovered": 0
},
{
"date": "2020-1-23",
"confirmed": 7,
"deaths": 0,
"recovered": 0
}],
"Albania": [
{
"date": "2020-1-22",
"confirmed": 3,
"deaths": 0,
"recovered": 0
},
{
"date": "2020-1-23",
"confirmed": 10,
"deaths": 0,
"recovered": 0
}]
}
For the past few days, I am trying to find a way to create an array that will host the sum of all confirmed cases for each day.
So let's say we have 2 days, and our array will have 2 elements, on the first element I want to have the sum of confirmed for each country for 2020-1-22 and on the second element, the confirmed for each country for 2020-1-23. So the array should look something like that:
[8 , 17]
This is probably something easy to do, but it seems I can't wrap my head around it to find a solution. I've studied similar solutions using reduce and map methods, but when I try to apply to my case, my brain simply gets too perplexed.
[8 , 17]from the posted JSON data. Could you please elaborate.