JS Array with timeout not working correctly
I want this array to write hello wait 1 second and write world wait a second and write !. but it doesn't do that what am i missing.
Code:
<script language="javascript">
var myArr = new Array();
myArr[0] = "Hello";
myArr[1] = "World";
myArr[2] = "!";
function wait(){
timeout = setTimeout(function(){test()}, 1000);//waits 1 second 10000 = 10 seconds
}
function test(){
window.clearTimeout(timeout);
for (i=0; i < myArr.length; i++){
console.log(myArr);
alert(myArr[i]);
wait();
}
}
test();
</script>