Merge two linear arrays into a two-dimensional array using map function - Javascript Array

Javascript examples for Array:map

Description

Merge two linear arrays into a two-dimensional array using map function

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  av a  2  s. co m*/
    var array1 = ["one","two","three"],
        array2 = ["1","2","3"],
        newarray = array1.map(function(c, i) { return [ c, array2[i] ] });
        console.log(JSON.stringify(newarray));
    }

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

Related Tutorials