https://stackoverflow.com/questions/14651348/checking-if-image-does-exists-using-javascript
Here I found how to check if image exist, though these returns Promise in which there is Boolean stating if image exists or no, I want to save this Boolean to variable so I can use it later, but not sure how to do it, tried many stuffs, but nothing works.
code in question
function imageExists(url) {
return new Promise(resolve => {
var img = new Image()
img.addEventListener('load', () => resolve(true))
img.addEventListener('error', () => resolve(false))
img.src = url
})
}
const url = 'http://www.google.com/images/srpr/nav_logo14.png'
imageExists(url)
.then(ok => console.log(`RESULT: exists=${ok}`))
// => RESULT: exists=true
I need it to return boolean, rather than console.log, for example
let imgExist = imageExists(url)
.then(ok => oK )
but this or other attempts dont work, dont really understand this syntax