Copy array by value - Javascript Array

Javascript examples for Array:push

Description

Copy array by 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(){//from   w  w w  .  j a  v a2  s  .  co  m


var arr1 = ['a','b','c'];
var arr2 = new Array(arr1);
arr2.push('d');  //Now, arr1 = ['a','b','c','d']
document.write(arr1);
document.write("<br />")
document.write(arr2);


    }

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

Related Tutorials