title: how to dynamically create an array of objects?
body: <p>I have an array of objects which is created by pulling data from a csv file. The array looks like the following (when printed). </p>
  
  <pre><code>Array[4]
  0:Object
      value1:"200"
      value2:"95"
      value3:"6395"
      value4:"2"
  1:Object
  2:Object
  3:Object
  </code></pre>
  
  <p>The way I created it is the following.</p>
  
  <pre><code>var strCSV = e.target.result;
  var arrCSV = strCSV.match(/[\w .]+(?=,?)/g);
  var noOfCols = 4;
  
  // To ignore the first row which is header
  var hdrRow = arrCSV.splice(0, noOfCols);
  
  var data = [];
  while (arrCSV.length &gt; 0) {
      var obj = {};
      // extract remaining rows one by one
      var row = arrCSV.splice(0, noOfCols)
      for (var i = 0; i &lt; row.length; i++) {
          obj[hdrRow[i]] = row[i].trim();
      }
      // push row to an array
      data.push(obj)
  }
  </code></pre>
  
  <p>So let's say now I want to create another array of objects, with the same data values, but different keys.</p>
  
  <pre><code>var tableData = [
          {key1: "", key2: "", key3: "", key4: ""}];
  </code></pre>
  
  <p>I've tried different ways to do I haven't been able to do it. For example I tried the following.</p>
  
  <pre><code>for(var i=0; i&lt;data.length; i++){
      console.log(i);
      tableData[i]["key1"] = data[i].value1;
  }
  </code></pre>
  
  <p>Or something with a similar form. I created an empty array tableData = [] thinking that creating the elements on the spot would do the trick, but it won't. Is there anyway to do this? I can't just create a object and copy all the elements from the first array one by one as the number of elements in the first array could be anything. </p>