Hello i was trying to modify an object form the values of another object
this is the one i need to modify :
y = {name:'m' , age:'28' , g:{m:'n' , f:'y' , k:'n' ,
other :{x:'f' , y:'m'}} , h:'6' , zip :'12345' } ;
the following object will loop in object y and if it found any matched element , it will change it’s value to match object x
x = {name :'y' , age:'17' , g :{m:'y' ,f:'n'}} ;
CODE
for(var i in x){
for(var o in y){
if(i == o) y[o] = x[i] ;
}
}
when this code runs it change the value of y.(name and age ) it keeps h and zip values as it is which is great
PROBLEM is at g object it only change the value of g.n and g.f and delete the rest of the g object element
jsFiddle example
what i was hoping to get is
y = {name:'y' , age:'17' , g:{m:'y' , f:'n' , k:'n' ,
other :{x:'f' , y:'m'}} , h:'6' , zip :'12345' }
i’m using jquery so if there is any jquery function that will help that’s fine
You can use
jQuery.extendwithdeepparameter: