Possible Duplicate:
What is the most efficient way to clone a JavaScript object?
I have an object like this:
User = {
name: "user",
settings: {
first: "1",
second: "2"
}
}
and a second one:
user1 = {
name: "user1",
settings: {
second: "3"
}
}
now I want to copy user1's custom values into User, using:
for(var key in user1){
User[key] = user1[key];
}
the result User will be:
User = {
name: "user1",
settings: {
second: "3"
}
}
User.settings has been entirely replace while I wanted only settings.second to be replaced.
How to achieve this, without knowing how much child object the main object have?