I have a promise/global object that outputs as follows in the console:
console.log(globalInfo);
Promise
__proto__:Promise
[[PromiseStatus]]:"resolved"
[[PromiseValue]]:globalInfo
item1:"12345"
item2:"something else"
item3:"www.stackoverflow.com"
__proto__:Object
And am successfully pulling out the value for "item2" as such:
globalInfo.then(function(val) {
newVar = val.item2;
console.log('newVar inside: ' + newVar);
});
console.log('newVar outside: ' + newVar);
But, I am not able to pass that variable/value outside of the then()
function. Nothing outputs to the console for the second console.log ("newVar outside").
How do I make the variable "newVar" with the the value for "item2" available globally outside of the then()
function?