title: Dynamic deep setting for a JavaScript object
body: <p>Given a string for a object property path, how do I set this property dynamically.</p>
  
  <p>Given this sample object:</p>
  
  <pre><code>var obj = {
      a: {
          b: [ { c: 'Before' } ]
      }
  };
  </code></pre>
  
  <p>It should be able to set the value with a helper function like this:</p>
  
  <pre><code>setToValue(obj, 'After', 'a.b.0.c');
  </code></pre>
  
  <p>I tried it with the following code. But parent is a copy if the variable not a reference.</p>
  
  <pre><code>function setToValue(obj, value, path) {
      var arrPath = path.split('.'),
          parent = obj;
  
      for (var i = 0, max = arrPath.length; i &lt; max; i++) {
          parent = parent[arrPath[i]];
      }
  
      parent = value;
  }
  </code></pre>