Skip to content

Instantly share code, notes, and snippets.

@v1talii-dev
Last active April 5, 2019 09:21
Show Gist options
  • Save v1talii-dev/572dc8f2a84493dccb0454d4259ed22d to your computer and use it in GitHub Desktop.
Save v1talii-dev/572dc8f2a84493dccb0454d4259ed22d to your computer and use it in GitHub Desktop.
JS diff object
function getObjectDiff(obj1, obj2) {
const diff = Object.keys(obj1).reduce((result, key) => {
if (!obj2.hasOwnProperty(key)) {
result.push(key);
} else if (_.isEqual(obj1[key], obj2[key])) {
const resultKeyIndex = result.indexOf(key);
result.splice(resultKeyIndex, 1);
}
return result;
}, Object.keys(obj2));
return diff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment