I'm trying to figure out how to save the output of a fetch to a variable. My aim is to use it as an object.
Here is my code:
async function getWeather() {
let response = await fetch('url');
let result = await response.json();
return console.log(result);
}
getWeather();
That code gives me the expected response
I tried to return the result instead of a console log and store it in a variable (let weather=getWeather();
) which gave me the promise object
when I console logged weather
.
I also tried another solution for this question that was answered here, but when I tried to console log the object outside of the fetch, I would get undefined.
Is there any other solution?