title: Javascript: creating new column in array of objects
body: <p>I have an array of objects like so:</p>
  
  <pre><code>var arr1 = [
      {"Date": "2017-04-15", "Price":"300"},
      {"Date": "2017-04-16", "Price":"310"},
      {"Date": "2017-04-17", "Price":"320"},
  ]
  </code></pre>
  
  <p>I wish to add a new key(<code>newDate</code>)-value(JS <code>Date</code> object) pair in each row. That is, I want to end up with:</p>
  
  <pre><code>[
      {"newDate":2017-04-14T14:00:00.000Z, "Date": "2017-04-15", "Price":"300"},
      {"newDate":2017-04-15T14:00:00.000Z, "Date": "2017-04-16", "Price":"310"},
      {"newDate":2017-04-16T14:00:00.000Z, "Date": "2017-04-17", "Price":"320"},
  ]
  </code></pre>
  
  <p>My script so far, which I run in <code>node</code>:</p>
  
  <pre><code>function getDateObject(dateString) {
      // Splits a yyyy-mm-dd string, and returns a Date object
      var parts = dateString.split("-")
      var myDate = new Date(parts[0], parts[1]-1, parts[2])
      return myDate
  
  
  for (var i = 0; i &lt; arr1.length; i++) {
      console.log(arr1[i])
      arr1[i]["newDate"] = getDateObject(arr1[i]["Date"])
  }
  </code></pre>
  
  <p>This gives an error:</p>
  
  <pre><code>TypeError: Cannot read property 'split' of undefined at getDateObject
  </code></pre>
  
  <p>That is, it's throwing at error at the line: <code>var parts = dateString.split("-")</code>. I'm puzzled by this syntax error because of course <code>dateString</code> is not defined; it's meant to be an input parameter, rather than a variable instantiated by <code>var</code>, <code>let</code> or <code>const</code> or something. Am I missing something?</p>
  
  <p>Bonus: would be great if someone could suggest a way to do this with <code>array.map</code>.</p>