Create empty array and then push value - Javascript Array

Javascript examples for Array:push

Description

Create empty array and then push value

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.  java 2  s  .  c o m*/
var namelist = [];
function draw() {
    console.log(namelist.join(', '));
}
function myFunction() {
    namelist.length = 0; // empty name list
    namelist.push('a');
    namelist.push('b');
    namelist.push('123');
    draw();
}
myFunction();
myFunction();
    }

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

Related Tutorials