This question has already been answered:

I have a function. This function should be called 10 times, each time after 10 seconds. I tried to do it like this, but it displays only once:

for (var i = 0; i <=10; i++) { setTimeout(funcBefore, 1000); } 

Reported as a duplicate at Grundy. javascript Nov 18 '16 at 11:58 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

3 answers 3

Alternate, shows iteration 10 times every 10 seconds

 function funcBefore(){ console.log('text'); } count = 0; intervalId = setInterval(function(){ count++; if(count == 10){ clearInterval(intervalId); } funcBefore(); }, 1000); 

  • She's endless - ttt
  • Updated. Take a look. - lazyproger

After 10 seconds, a cycle of 10 iterations starts with a function call

 function funcBefore (i) { console.log(i); } setTimeout(function() { for (var i = 0; i < 10; i++) { funcBefore(i); } }, 10000); 
  • If I understand the question correctly (before editing). - Nikolai Smekalov
  • All the same 1 time displayed. I need to display 10 times. For example, the function to display the words "admin". The result should be like this: admin admin admin admin admin ... - ttt
  • Every time 10 seconds! - lazyproger

 function funcBefore() { console.log("funcBefore"); } setTimeout( function() { for (var i = 0; i <= 10; i++) funcBefore(); }, 10000 ); 

  • @Visman, after the same - Grundy Nov.
  • @Grundy, exactly, in 1 :) So I think the question I edited correctly or not. - Visman Nov.
  • All the same 1 time displayed. I need to display 10 times. For example, the function to display the words "admin". The result should be like this: admin admin admin admin admin ... - ttt
  • @ttt click the "Run code" button and look at the 10 pins of the funcBefore line - Anton Shchyrov
  • there everything is immediately displayed. I need everything to complete in turn - ttt