JavaScript Object  Comparisons

Determine equality for two JavaScript objects

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

Meet the Author

Kevin Leary, WordPress Consultant

I'm a freelance web developer and WordPress consultant in Boston, MA with 17 years of experience building websites and applications. View a portfolio of my work or request an estimate for your next project.