Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  34] [ 7]  / answers: 1 / hits: 23342  / 13 Years ago, wed, january 18, 2012, 12:00:00

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?


More From » javascript

 Answers
14
if (data['results'][res]['entities']['media'][0] == undefined
|| data['results'][res]['entities']['media'][0] == null) {

...
}

[#87934] Tuesday, January 17, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
stefanicarolinat questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Fri, Apr 16, 21, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;