parsing a JSON fails with missing element in javascript
I am trying to use Youtube's Gdata JSON response in javascript. My code
iterates through the playlist and extract the item data.but for few videos
the rating is not there which throws
"TypeError: item.gd$rating is undefined"
is there a way to check before accessing the element.
this is the code with with i fetch the json response.
var avgrating = item['gd$rating']['average'];
var maxrating = item['gd$rating']['max'];
var minrating = item['gd$rating']['min'];
var numRaters = item['gd$rating']['numRaters'];
No comments:
Post a Comment