title: Javascript - nested arrays transformed to array of objects
body: <p>I have a nested array data structure like this - </p>
  
  <pre><code>var arrays = [
          [
              ['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk']
          ],
          [
              ['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager']
          ]
      ];
  </code></pre>
  
  <p>and I need to transform this into an array of objects  - </p>
  
  <pre><code>[
          {firstName: 'Joe', lastName: 'Blow', age: 42, role: 'clerk'},
          {firstName: 'Mary', lastName: 'Jenkins', age: 36, role: 'manager'}
      ]..
  
  
  
      My code below gives- 
  
      function objectArray(arr) {
        var obj1 ={};
        var empData=[];
          for (var i = 0; i &lt; arr.length; i++)
          {
              if (Array.isArray(arr[i]))
                  { 
                    arr[i].reduce(function(acc,prd){
                     // console.log(prd);
                         console.log(acc.key=prd[0],acc.Value=prd[1]);//--&gt; output shown below
                         return acc;
                    },{});
                  }
          }
      }
  
       var returnArrayOfObjs = objectArray(arrays);
       var empData = [];
       empData.push(returnArrayOfObjs);
       console.log(empData);  
  </code></pre>
  
  <p><em>The above log statement gives me an [undefined] as shown below in my output -</em></p>
  
  <h2>The output I get is as below - What am I doing wrong? Pls help!</h2>
  
  <pre><code>firstName Joe
  lastName Blow
  age 42
  role clerk
  firstName Mary
  lastName Jenkins
  age 36
  role manager
  [undefined]
  </code></pre>