JSFiddle - React, Tailwind, and code Playground
by radu
JavaScript
var snapShot = {
name: "Joe",
address: "123 Main Street",
age: 30,
favoriteColorPriority: {
yellow: 1,
pink: 2,
blue: 3
}
};
var liveData = {
name: "Joseph",
address: "123 Main Street",
age: 30,
favoriteColorPriority: {
yellow: 1,
pink: 3,
blue: 2
}
};
var getChanges = function(current, reference) {
var differences = {};
for (var prop in reference) {
if (current.hasOwnProperty(prop) && current[prop] !== reference[prop]) {
differences[prop] = current[prop];
}
}
return differences;
}
console.log(getChanges(liveData, snapShot));