title: javascript: access object (array) by array notation string
body: <p>I would like to access the object provided only it's string path in form of array is known.</p>
  
  <p>1.) there is an object, where</p>
  
  <pre><code>root["obj1"]["obj2"] = 1;
  </code></pre>
  
  <p>(in common case <code>root["obj1"]...["objN"]</code>)</p>
  
  <p>2.) I have ONLY string objectPath known:</p>
  
  <pre><code>var objectPath = 'root["obj1"]["obj2"]'
  </code></pre>
  
  <p>3.) I need NOT only READ the object, but SET it's value, like</p>
  
  <pre><code>objectPath = 2;
  //so root["obj1"]["obj2"] === 2
  </code></pre>
  
  <p>As I understand </p>
  
  <ol>
  <li><p>there might be some options with eval(), but it gets the value, not the variable; </p></li>
  <li><p>one can loop through all objects of root, make convertion to "root.obj1.obj2" (which is not the case, as "obj1" can easily be "obj with spaces1") and check if given string equals to current object in the loop.</p></li>
  </ol>
  
  <p><a href="http://jsfiddle.net/ACsPn/" rel="nofollow noreferrer">http://jsfiddle.net/ACsPn/</a></p>
  
  <p>Related Link: 
  <a href="https://stackoverflow.com/questions/8051975/access-object-child-properties-using-a-dot-notation-string">Access object child properties using a dot notation string</a></p>