title: JavaScript object pushed into an array
body: <blockquote>
    <p><strong>Possible Duplicate:</strong> <br/>
    <a href="https://stackoverflow.com/questions/728360">How do I correctly clone a JavaScript object?</a></p>
  </blockquote>
  
  
  
  <p>I have this code:</p>
  
  <pre><code>var temp = [];
  var obj = {name:"1"};
  temp.push(obj);
  obj.name = "2";
  temp.push(obj);
  </code></pre>
  
  <p>What I'm expecting to be true:</p>
  
  <pre><code>temp[0].name == "1" &amp;&amp; temp[1].name == "2";
  </code></pre>
  
  <p>What actually happens:</p>
  
  <pre><code>temp[0].name == "2" &amp;&amp; temp[1].name == "2";
  </code></pre>
  
  <p>Why does this happen, and how I can get what I'm expecting?</p>