Skip to content

Instantly share code, notes, and snippets.

@danieldunderfelt
Last active August 29, 2015 14:01
Show Gist options
  • Save danieldunderfelt/4525d19f2fa761d9ea77 to your computer and use it in GitHub Desktop.
Save danieldunderfelt/4525d19f2fa761d9ea77 to your computer and use it in GitHub Desktop.
Compare keys and values of two objects
/**
* Use this to compare one object's properties to corresponding properties on another object.
* Returns true if b contains all of the properties of a with the same values. Object b
* can contain more properties than object a, the important thing is that the values
* and property names of a are found on b. Enumerable properties only!
*/
function compare(a, b) {
var isEqual = [];
var keys = Object.keys(a);
keys.forEach(function(prop, id, obj) {
if( a[prop] === b[prop] ) isEqual.push(true);
});
return isEqual.length === keys.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment