I need to replace imagesrc with the value stored in this object. However when I run:
if(data['results'][res]['entities']['media']["0"]["media_url"]) {
imagesrc = data['results'][res]['entities']['media']["0"]["media_url"];
}
I get the error:
Cannot read property '0' of undefined
How can I run my condition so that I don't get errors if something is undefined?
if (data['results'][res]['entities']['media']["0"] == undefined
|| data['results'][res]['entities']['media']["0"] == null) {
...
}
you can place your code inside a try catch
block and examin error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With