Menu
I’m trying to create an image rotator, but whenever I try to access an array element within the loop (only within setTimeout()), I’m just getting a value of ‘undefined’.
[code=php]images = new Array(“test1”, “test2”, “test3”);
for (var i = 0; i < images.length; i++) {
setTimeout(function() { alert(images[i]); }, i*500);
}
If I had to guess, I would say that images[] is no longer in scope when the function is actually executed. Is this the case? Thanks!