The lodash library’s isEqual() method provides a deep comparison between two JavaScript objects:

var user1 = { name : "nerd", org: "dev" };
var user2 = { name : "nerd", org: "dev" };
( user1 == user2 ) // returns false - NO WORKY
_.isEqual( user1, user2 ); // return true - WORKS

I’ve found it quite handy in my day to day, if you need a way to compare JavaScript objects in Node.js or client-side JS it’s a the best option. If you’re like me and you want to know more about what’s going on here take a look at the eq() pulled from underscore.js in the lodash GitHub source

About the Author

Kevin Leary is a freelance web developer in Boston, MA specializing in enterprise WordPress development, conversion optimization and JavaScript development.