I'm currently developing a Covid-Tracker application using Angular and an open REST API (here).
My goal is to retrieve the number of confirmed cases from the past 30 days in a specific country. This is an example of the response structure:
https://i.sstatic.net/0suUo.png
Within my Angular project, I am extracting the cases
data from the JSON response with the following code:
covid.service.ts
getHistoricalData(country: string): Observable<any> {
return this.http.get<any>(`${this.URL}/historical/${country}`);
}
dashboard.component.ts
this.covidService.getHistoricalData('poland').subscribe(res => {
let cases = res.timeline.cases;
console.log(cases);
});
}
The output displayed in the browser's console is as follows:
https://i.sstatic.net/5trnN.png
However, I'm facing a challenge in storing this output as key-value pairs, where the key represents the date and the value signifies the number of cases on that particular day. I attempted using a Map
, but I'm unsure how to extract the relevant date and its corresponding value. Any advice on how to achieve this would be greatly appreciated.