Javascript: Get deep value from object by passing path to it as string
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key">Accessing nested JavaScript objects with string key</a>  </p>
</blockquote>



<p>Maybe the title is not clear enough, I just didn't know how to specify what I'm looking for and my English is really bad, sorry.</p>

<p>I'm trying to create function that returns object value, but also plays nice with nested objects. For example:</p>

<pre><code>var obj = {
  foo: { bar: 'baz' }
};
</code></pre>

<p>I want to access the value of obj.foo.bar by suppling the string "foo.bar" to the function.</p>

<pre><code>function(obj, path) {
  // Path can be "foo.bar", or just "foo".
}
</code></pre>

<p>Thanks!</p>
