Using Javascript, I'm trying to loop through an array and execute a function with a time delay on each loop. This does not work:
<script type="text/javascript">
movesArray = new Array("s","s","s","s","s","s","s","s","s","s","s","s","s","s");
var pause = 100;
for (i=0; i<=14; i++)
{
var t=setTimeout("ProcessKeypress(movesArray[i])", pause);
pause = pause+100;
}
</script>
However, if I just repeat it multiple times it does work:
<script type="text/javascript">
var t=setTimeout("ProcessKeypress('s')", 100);
var t=setTimeout("ProcessKeypress('s')", 200);
var t=setTimeout("ProcessKeypress('s')", 300);
var t=setTimeout("ProcessKeypress('s')", 400);
var t=setTimeout("ProcessKeypress('s')", 500);
</script>
The problem is that in some cases I will need to repeat the function a few hundred times (maybe more) which creates a large webpage. Is there a way to loop through the array and run the function on a time delay?