Merge Multiple Column of Arrays to rows with map function - Javascript Array

Javascript examples for Array:map

Description

Merge Multiple Column of Arrays to rows with 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  ww w.  j ava  2 s. c o  m*/
var obj = {
    A: [1, 2, 3],
    B: [4, 5, 6]
}
var keys = Object.keys(obj);
var desiredStructure = obj[keys[0]].map(function(col,i){
    return keys.map(function(_,j){ return obj[keys[j]][i] })
});
console.log(desiredStructure);
    }

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

Related Tutorials