title: How to dynamically create dot notation object path to push data into an array
body: <p>The view I have is updated when this.dataSource.data is updated.  I want to push() new objects into a deeply nested object dynamically. I currently am feeding an array of viewValue names into a forEach() loop that first finds the index and, with this index, paths it's way down to the desired leaf node.</p>
  
  <p>The issue I'm having is that I need to set this equal to this.dataSource.data, but as I'm digging into the nested object, I'm unable to keep the dot notation path.</p>
  
  <p>I thought I could store the path as a string and convert it with eval() or something, but this seems sloppy, and I haven't gotten that to work either(it usually says that data in this.dataSource.data is undefined, which I'm not sure why.  maybe it's a bug with the chrome debugger).</p>
  
  <p>I have a feeling there is a simple answer, but my dumb eyes can't see it.
  I've looked for similar things on stack overflow, but haven't found anything that really is similar, even though there has to be, as this seems like a seemingly common sounding problem.  Maybe, I'm just really bad at google searches.</p>
  
  <p>EDIT:  I don't think tracking the path via string and converting the string to an object path is the best approach.  this would be a last resort, i think.</p>
  
  <p>Edit2: made <code>'.[results]'</code> to <code>'["results"]'</code> removing the <code>.</code></p>
  
  <pre class="lang-js prettyprint-override"><code>let pathingObject = this.dataSource.data
  let pathingString = 'this.dataSource.data'
  if (pathingArray === null) {
    this.serviceData.push(data)
    console.log(this.serviceData);
    this.dataSource.data = this.serviceData
  } else {
    pathingArray.forEach(element =&gt; {
      let index = pathingObject.findIndex(p =&gt; p.viewValue == element);
      pathingObject = pathingObject[index]['results']
      pathingString = pathingString + '[' + index + ']' + '["results"]';
    });
    pathingObject.push(data);
    //console.log(eval(pathingString));
    // this.dataSource.data = pathingObject;
  }
  </code></pre>