set an object property with sugar like obj['level1.level2.leve3'] = value
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13534116/get-element-on-any-level-of-an-object-in-javasscript">Get element on any level of an object in Javasscript</a>  </p>
</blockquote>



<p>Good day for every one!
I'am really confused with this one:</p>

<p>I have an Object:</p>

<pre><code>var someObject = {}
</code></pre>

<p>So, next I wanna set properties like this:</p>

<pre><code>someObject['errors.email'] = value1;

someObject['errors.password'] = value2;
</code></pre>

<p>and after have an object:</p>

<pre><code>{
   errors: {
              email: 'some value 1'
              ,password: 'some value 2'
           }
}
</code></pre>

<p>is it possible with some syntactic sugar?</p>

<h1>The most sweet issue is</h1>

<pre><code>function setValueByPath(obj, path, value) {
var pathArray = path.split('.');
    var pointer = obj;
    var i = 0, l = pathArray.length-1, prop;

    for (; i&lt;l; i++) {
        prop = pathArray[i];
        pointer = pointer.hasOwnProperty(prop) ? pointer[prop] : (pointer[prop] = {});
    }

    pointer[pathArray[i]] = value;
}
</code></pre>

<p>thanks to Roman Ziva for advice (see here <a href="http://jsperf.com/autocreate-obj" rel="nofollow">http://jsperf.com/autocreate-obj</a>)</p>

<p>an example see here <a href="http://jsfiddle.net/zafod/KxesD/" rel="nofollow">http://jsfiddle.net/zafod/KxesD/</a></p>
