I have an arrays=[John; Alex; Mark]
, I wanna to show the elements of this array one by one by 3 second delay.
for (var i=0; i<=3; i++)
{
Try this without pseudo-recursion
var arr = [10,20,30,40]; // your array
var i = 0;
var interval = 2000 // 2 sec, you can add your time required
function callInterval() {
// set a variable for setInterval
var time = setInterval(()=>{
console.log('['+arr[i]+','+i+']');
i++;
if(i==arr.length){
this.clearInterval(time);// clear the interval after the index
}
}, interval);
}
callInterval();