I am trying to display images into thumbnails for my image gallery by using for...in loop but it is only able to display one image. I am still a beginner in javascript, so my understanding of for loops is still not good. Where did I go wrong?
sample array:
["http://tos-staging-web-server-s3.s3.amazonaws.com/9/catalogue/apples_in_season.png",
"http://tos-staging-web-server-s3.s3.amazonaws.com/9/catalogue/apples_in_season.png"]
for...in loop:
for(var thumb in thumbnails) {
$('.thumbnail img').attr({"src":[thumbnails[thumb]]});
}
thumbis already the value,$('.thumbnail img').attr({"src":thumb});thumbis the key:0, then1. You need ES6for (var thumb of thumbnail)for what you are saying. OP,srcshould not be an array:attr({"src": thumbnails[thumb] }). Also, you're setting all the thumbnail images to one value, then another, which is probably not what you want (then again, your whole array has the same value...)thumbthe key?