Make for loop log line by line with 1 sec delay - Javascript Statement

Javascript examples for Statement:for

Description

Make for loop log line by line with 1 sec delay

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from ww  w.  j  a  v  a  2s .  co  m*/
function log(offSet) {
  setTimeout(() => {
    const str = new Array(offSet + 1).join('*');
    console.log(str);
  }, 1000 * offSet);
}
for(let i = 1; i < 11; i ++) {
  log(i);
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials