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 developer in Boston, MA with a strong portfolio of work, and over 13 years of experience as a programming consultant and digital strategy provider. Interested in working together? Hire me for your next project.