Creating a Function to select individual items out of an array JavaScript - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Creating a Function to select individual items out of an array JavaScript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <button onclick="PickNum()">Pick</button> 
      <br> 
      <h1 id="cal1"></h1> 
      <script>
   var my = [ " 1 ", " 2 ", " 3 ", " 4 " ];
   var loopz = 0/*  w w w  .j  av  a2  s .c o m*/
    function PickNum() {
        document.getElementById('cal1').innerHTML= my[loopz];
            if(loopz < my.length -1){
               loopz++ 
            } else {
               loopz = 0
            };
        }

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

Related Tutorials