jQuery.each breaks on undefined object
by Akram kamal
HTML
<div class="content"></div>
JavaScript
var person =[{
'name': 'john',
'age':12,
'img': [
{
'thumb' : 'http://placehold.it/75x75',
'full' : 'http://placehold.it/200x200'
}
]
},
{
'name': 'Mat',
'age':12
},
{
'name': 'Mat',
'age':12
},
{
'name': 'Kirk',
'age':12,
'img': [
{
'thumb' : 'http://placehold.it/75x75',
'full' : 'http://placehold.it/200x200'
}
]
}]
$.each(person, function(i,v){
if (v.img)
$('.content').append('<img src="'+ v.img[0].thumb +'">')
})