Get array element one by one with timer setTimeout() - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Get array element one by one with timer setTimeout()

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(){// www  .  j  a  v  a 2s . co  m
var skins = ["%k", "%m", "%s", "%b"];
var skin;
function changeSkin(i) {
  skin = skins[i = (i && i < skins.length) ? i : 0];
  console.log(skin);
  setTimeout(changeSkin, 1000, ++i);
}
changeSkin();
    }

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

Related Tutorials