0
How can one print individual items in an array in a specific time interval with JavaScript
JavaScript coding
2 Antworten
+ 2
Use setInterval for a specific time interva to print an array
+ 2
In order to understand, you got to write a code to demo it.
It is not inly using setInterval function, it also need clearInterval to stop the printing when index of array is over length of array.
const arr = ["apple", "orange", "kiwi", "manggo", "banana"];
let i = 0;
const tm = setInterval(function () {
console.log(arr[i++]);
if(i === arr.length) clearInterval(tm);
},100);
https://code.sololearn.com/cexuktXuEcRH/?ref=app