How can one print individual items in an array in a specific time interval with JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can one print individual items in an array in a specific time interval with JavaScript

JavaScript coding

29th Aug 2020, 6:50 AM
Rex Nerdy
Rex Nerdy - avatar
2 Answers
+ 2
Use setInterval for a specific time interva to print an array
29th Aug 2020, 7:07 AM
Akash Agrawal
Akash Agrawal - avatar
+ 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
29th Aug 2020, 8:48 AM
Calviղ
Calviղ - avatar