How can I save a value of a promise in javascript already tried with this
function loadImage(url){
return new Promise((resolve, reject) => {
const image = new Image();
image.addEventListener('load', () => {
resolve(image);
});
image.src = url;
});
}
var image = loadImage(image);
image.then(result => {
return result;
});
And it does not work I get something like that when I print the variable in the console.
Promise {<pending>}
__proto__
:
Promise
[[PromiseStatus]]
:
"resolved"
[[PromiseValue]]
:
img
But if I print the image variable from the loadImage function inside the promise I get the normal image configuration.