Repack array after loop - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Repack array after loop

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(){/*ww w.  j ava  2 s .c  o m*/
var btn = document.getElementsByClassName('btn');
var a = [];
for(i=0; i<btn.length; i++){
   a.push(btn[i].value);
   console.log(a[i]);
}
console.log(a[a.indexOf("Windows")]);
    }

      </script> 
   </head> 
   <body> 
      <input class="btn" type="submit" value="Windows">
      <br> 
      <input class="btn" type="submit" value="Linux">  
   </body>
</html>

Related Tutorials