title: Find and replace object inside object
body: <p>I want to dinamically replace object inside parent object.</p>
  
  <p>Object:</p>
  
  <pre><code>var obj = {
      address: { id: 2, type: { id: 1, label: 'Test1' } },
      id: 1,
      name: 'test'
  }
  </code></pre>
  
  <p>Selector:</p>
  
  <pre><code>var selector = "address.type";
  </code></pre>
  
  <p>New inner object:</p>
  
  <pre><code>var type = { id:2, label: 'Test2' }
  </code></pre>
  
  <p>Now, what is the best way to replace "obj.address.type" with "type"?</p>
  
  <p>My attemtp</p>
  
  <pre><code>tmp = selector.split('.'), obj1 = obj;
  for(prop in tmp) {
      obj1 = obj1[tmp[prop]];
  }
  </code></pre>