title: Combining two arrays to form a javascript object
body: <p>I have two arrays:</p>
  <pre><code>var columns = [&quot;Date&quot;, &quot;Number&quot;, &quot;Size&quot;, &quot;Location&quot;, &quot;Age&quot;];
  
  var rows = [
    [&quot;2001&quot;, &quot;5&quot;, &quot;Big&quot;, &quot;Sydney&quot;, &quot;25&quot;],
    [&quot;2005&quot;, &quot;2&quot;, &quot;Med&quot;, &quot;Melbourne&quot;, &quot;50&quot;],
    [&quot;2012&quot;, &quot;20&quot;, &quot;Huge&quot;, &quot;Brisbane&quot;, &quot;80&quot;]
  ];
  </code></pre>
  <p>I'm trying to combine them into a javascript object for each item in the rows array. After that, I want to push each object into a new array.</p>
  <p>Like:</p>
  <pre class="lang-js prettyprint-override"><code>var newarray = [];
  
  //'thing' should be the same structure for each row item
  var thing = {
    &quot;Date&quot;: &quot;2001&quot;,
    &quot;Number&quot;: &quot;5&quot;,
    &quot;Size&quot;: &quot;Big&quot;,
    &quot;Location&quot;: &quot;Sydney&quot;,
    &quot;Age&quot;: &quot;25&quot;
  }
  
  newarray.push(thing);
  </code></pre>
  <p>I can do this when I know the names of the columns, but I need to be able to store the data in this way when the column name is unknown - i.e. based on the indexes of the columns array.</p>
  <p>I tried it like this before:</p>
  <pre class="lang-js prettyprint-override"><code>for (var y = 0; y &lt; rows.length; y++) {
  
    for (var i = 0; i &lt; columns.length; i++) {
      thing[columns[i]] = rows[i][i];
    }
    newarray.push(thing)
  }
  </code></pre>
  <p>The code above only stored the first item again and again (according to rows.length).</p>
  <p>I don't understand how to combine the column names with the rows to create an array of objects. The fact that 'rows' contains arrays is especially confusing..</p>