• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: response.map is not a function – type error?

Resolved: response.map is not a function – type error?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to get a list of countries from an API and this is how I’m doing it.
My code compiles and builds but at runtime it tells me that response.map is not a function and when I try to log the length of the list it returns undefined. I can’t seem to figure out why the response variable is not being recognised as a list. Below, I have also added what CovidInfo and getCountries looks like

Answer:

Check the API: https://covid19.mathdro.id/api/countries
I can see the response format is:
So when your 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!

node.js reactjs web-frontend
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Resolved: How to separate multiple answers in one column, for multiple columns, by creating extra columns

26/03/2023

Resolved: How to set consistent decimal separators in R data frame?

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.