Question:
I’m trying to get a list of countries from an API and this is how I’m doing it.Answer:
Check the API: https://covid19.mathdro.id/api/countriesI can see the response format is:
getCountries
returns response.json()
it’s returning an object, not an array. That is why length
is undefined and map
is not a function.The list of countries you want is inside the property
countries
.For it to work you can change your code to something like:
If you have better answer, please add a comment about this, thank you!