132
rated 0 times
[
134]
[
2]
/ answers: 1 / hits: 21983
/ 12 Years ago, wed, january 23, 2013, 12:00:00
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?
More From » javascript