Can anyone help me how to loop in an object with the property of that object has another object and so on.
ex.
var You = {
child: {
name: {
first: 'John',
last: 'Doe'
}
},
extend: function(object) {
// implementation to extend this current object
}
};
var childrenOf1stWife = {
child: {
name: {
first: 'Steve',
last: 'Jobs',
company: 'apple'
}
},
adopted: {
name: {
first: 'Bill',
last: 'Gates',
children: {
son1: 'Foo',
son2: 'Bar'
}
}
}
};
You.extend(childrenOf1stWife);
P.S. My purpose is to extend the default data; the answer Access / process (nested) objects, arrays or JSON mentioned differs from what I like. The answer only here return an array, or an object. What I would like is to extend the current objects property. So something that exist or not on the current object will be altered or added.
Expected results:
property of child of You will be changed with child property of childrenOf1stWife but before doing that, it checks to see if that child
property has a property of type 'object', then look again in that object. If the deep object has the same property if not, it will extend again.
And so on...