I'm trying to create a loop with a setTimeout in console log browser. But it is not working. I tried searching but have not found what I needed. Basically in each loop would be 5sec intervals during this printa 5sec in late updates. Would have to bring an array into the loop.
var myArray1 = new Array( "orange", "blue", "white" );
for (var i = 0; i <= myArray1.length; i++) {
console.log("This fruit" + myArray1[i] + "is delcious!");
setTimeout(function(){ alert() }, 500); //AFTER FIVE SECONDS
setTimeout(function(){
} //CLOSE FOR
}, 5000); //AFTER FIVE SECONDS
Let me give an example that I used and it works, but the code is too large. I wanted a way to better understand loop.
var myArray1 = new Array( "orange", "blue", "white" );
var var_time = 7000;
setTimeout(function(){
console.log("Fruit is " + myArray1[0]);
console.log("...stage 1 loading");
setTimeout(function(){
console.log("Fruit is " + myArray1[1]);
console.log( "...stage 2 loading");
setTimeout(function(){
console.log("Fruit is " + myArray1[2]);
console.log( "stage 2 finish");
alert();
console.log( "You code run perfect");
}, var_time); //stage 2
}, var_time); //stage 1
}, 500); //stage 0