title: Javascript deep copying object
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object">What is the most efficient way to clone a JavaScript object?</a>  </p>
  </blockquote>
  
  
  
  <p>I have an object like this:</p>
  
  <pre><code>User = {    
    name: "user",
    settings: {
      first: "1",
      second: "2"    
    }    
  }
  </code></pre>
  
  <p>and a second one:</p>
  
  <pre><code>user1 = {
    name: "user1",
    settings: {
      second: "3"
    }
  }
  </code></pre>
  
  <p>now I want to copy user1's custom values into User, using:</p>
  
  <pre><code>    for(var key in user1){
          User[key] = user1[key];
      }
  </code></pre>
  
  <p>the result User will be:</p>
  
  <pre><code>User = {
    name: "user1",
    settings: {
      second: "3"
    }
  }
  </code></pre>
  
  <p>User.settings has been entirely replace while I wanted only settings.second to be replaced.</p>
  
  <p>How to achieve this, without knowing how much child object the main object have?</p>