DEV Community

Discussion on: Javascript: How to access the return value of a Promise object

Collapse
 
metawops profile image
Stefan Wolfrum

Great article, helped me a lot to understand this concept! 👍👍
One question: suppose this fetch() call is inside a function. How would I return the JSON object from that function back to the main JS area where I made the call to the function? I tried a "return a;" just after the "console.log(a);" but that didn't work. Then I tried "return printAddress();", which didn't work either.
Any help? 😳

Collapse
 
ramonak profile image
Katsiaryna (Kate) Lupachova

I'd say that the only way to get this JSON object outside the fetch() call is to assign it to a variable. If you could provide your piece a code it would be easier to understand and to help:)