I am using a weather API to fetch data for a specific city, but i'm receiving the data in a list with 5 duplicates. I need to use the city name, minTemp, maxTemp, etc. within my app.
Essentially, I just need one of the 5 objects inside the response object, but I'm not sure how I can extract and use just one.
const apiCall = await fetch(
`http://api.openweathermap.org/data/2.5/find?q=London&appid=${weatherAPIKey}`
);
const response = await apiCall.json();
this.setState({
city: response.list.name,
country: response.list.sys.country,
});
Will appreciate any help!
If you're sure that all 5 objects is the same, then just access the first one (or any one)
const response = await apiCall.json();
const firstCity = response.list[0]
const { name, country } = firstCity
this.setState({
city: name,
country,
});