I'm new to Javascript and i'm trying to fetch and display some images asynchronously. Here is what i've tried so far,
for (i=0; i<10; i++){
var _image= new Image();
_image.onload = function(){
var id= "image".concat(i);
document.getElementById(id).src = this.src;
};
_image.src = urls[i]);
}
As expected when the onLoad
event fires i
does not start from zero, thus images don't display correctly. What's the proper way to do this?