javascript - console says I have error what is it? -
my code working fine when check in console on google chrome error. out of curiosity know means code seems working fine.
heres code:
var images = []; var imageindex = 0; var $mainimage = $(".thumb-large img"); var $maincaption = $(".thumb-large p"); var $thumbnails = $(".thumbnails img"); //var $mainname = $(".thumb-large-descrip p.name") function showimage(index) { $mainimage.attr({src: images[index].source});// error showing $maincaption.text(images[index].caption); $mainimage.attr({name: images[index].artistname}); }
i gave snippet of code says error. below google chrome console says :
uncaught typeerror: cannot read property 'source' of undefined
just looking on advice on means??? let me know if need more information.
the array var images = [];
not contain elements.
if array var arr = ['a','b','c']
, tried accessing arr[5]
, return undefined
. happening here.
add data array.
in case, like:
var images = [ { source: 'http://placehold.it/350x150', caption: 'this thing', artistname: 'troy beckett' }, { source: 'http://placehold.it/250x250', caption: 'another thing', artistname: 'troy beckett' } ];
Comments
Post a Comment