I have read through various posts regarding async/await but am still having trouble implementing this simple action.
const endpoint = 'http://api.openweathermap.org/data/2.5/weather?q=Oakland&APPID=54d05c3dfefbf06b604ba3ffcaaabdcf'
const weather = [];
fetch(endpoint)
.then(response => response.json())
.then(data => weather.push(...data));
console.log(weather)
// returns blank arr []
I just want to have my data in an array to work with. I believe this is because fetch
is running before const weather
is defined? If somebody could quickly tell me what to put where, I would be very thankful.
NOTE: I have read How do I return the response from an asynchronous call? and am still having issues.