Absolute JS newbie here. I am able to use fetch() to get JSON from a URL but I can’t figure out how to do anything with that JSON outside of the fetch itself.
Here’s my code (API key and GPS redacted):
fetch('https://www.airnowapi.org/aq/forecast/latLong/?format=application/json&latitude=X&longitude=X&distance=50&API_KEY=X')
.then(result => result.json())
.then((out2) => {
console.log('Fetch Output: ', out2);
}).catch(err => console.error(err));
Any code that references out2 other than console.log() call gives an error that out2 is undefined. How do I get access to out2 anywhere else?
You must log in or register to comment.