I have 2 objects, one of which starts as a copy of the other. I would like to be able to check if a different values have changed i.e. that they no longer match:
var obj = {
key1: {
innerKey: "val"
},
key2: "matching val"
};
var copy = {
key1: {
innerKey: "non-matching val"
},
key2: "matching val"
};
I would like to have some sort of hasChanged() method which would work something as follows:
hasChanged(obj.key1.innerKey); // result true
hasChanged(obj.key2); // result false
It seems I need some way to get the "path" or location of the property in order to find that property on the other object for comparison, but I'm not sure how to go about doing that.
Thanks
hasChanged(obj1, obj2, "key1.innerKey"). Then, you can look for that property on both objects by parsing it into it's pieces and looking it up on both objects.