Angular 4 setTimeout() with variable delay and wait

You can use IIFE (Immediately Invoked Function Expression) and function recursion instead. Like this:

let i = 0;
(function repeat(){
  if (++i > 5) return;
  setTimeout(function(){
    console.log("Iteration: " + i);
    repeat();
  }, 5000);
})();

Live fiddle here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)