Fill Array with push() method - Javascript Array

Javascript examples for Array:push

Description

Fill Array with push() method

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  va2s  . c  o  m*/
var myArray = [];
for(var i = 0; i < 5; i++)
{
    myArray.push("Item number " + (i + 1));
}
console.log("i = " + i);
console.log("myArray.length = " + myArray.length);
console.log("myArray[i] = " + myArray[i]);
console.log("myArray[4] = " + myArray[4]);
    }

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

Related Tutorials