Suppose there are two objects
source = {
name: "A",
address: {
city: "B",
zipcode: "C"
},
car: {
make: "D",
model: "E"
}
};
target = {
name: "",
address: {
city: ""
}
};
Now I want to copy all data from source over to target. However, copying must only take place, if the corresponding property already exists in the target. It is something like jQuery's extend, without adding new properties. With the above data the result will be...
target = {
name: "A",
address: {
city: "B"
}
};
How can this be achieved easily?