Possible Duplicate:
How do I correctly clone a JavaScript object?
I have this code:
var temp = [];
var obj = {name:"1"};
temp.push(obj);
obj.name = "2";
temp.push(obj);
What I'm expecting to be true:
temp[0].name == "1" && temp[1].name == "2";
What actually happens:
temp[0].name == "2" && temp[1].name == "2";
Why does this happen, and how I can get what I'm expecting?