I'm trying to understand promises better and have implemented code that basically looks like this:
console.log(getRemoteData())
function getRemoteData (){
return fetch('http://w.x.y.z')
.then(response => {
return response.json();
});
}
Assuming that getRemoteData()
returns a promise, how do I access the value of that response? I've tried to resolve the promise before logging to the console and I can't get it to do anything but log the promise obj. I think I'm missing a fundamental component of how promises work.
I've tried searching SO and all the answers I find point to a //do something with the returned data
comment in the .then()
method but I'd like to learn what I should do from there. The returned value is an array[]
.