There is an array that contains a certain number of elements (lines), which it must output one element every 5 seconds on a timer. The catch is that there may be a different number in the array of elements ...

Array example:

var mass = ["elem_1", "elem_2, "elem_3"]; 

How can you solve such a problem?

    1 answer 1

      var arr = ['elem_1', 'elem_2', 'elem_3'], i = 0, timerID; timerID = setTimeout(function tick () { if (i < arr.length) { console.log(mass[i]); i++; timerID = setTimeout(tick, 5000); } }, 5000);