Noob question here. Can someone elaborate on why seriesData
variable outside the then
scope is still an empty object. Additionally, what's the appropriate way of accessing data outside of said scope?
fetchData
is a method that returns an array of three objects when successfully resolved.
Obviously, the console.log
inside the then
scope prints the expected seriesData
object with the resulting data from the resolved promise.
Here's the code.
import fetchData from './data';
const seriesData = {};
fetchData()
.then(res => {
seriesData.characters = res[0];
seriesData.locations = res[1];
seriesData.episodes = res[2];
console.log(seriesData);
})
.catch(error => console.error(error.message));
console.log(seriesData);