4

Possible Duplicate:
How do you determine equality for two JavaScript objects?
Object comparison in JavaScript

Are there any javascript libraries that can help with comparing two objects for equivalence? So if I have something like

var obj1 = {"name":"Jeff", "gender":"M", "arrayprop":[1,2,3] };
var obj2 = {"name":"Jeff", "gender":"M", "arrayprop":[1,2,3] };

And I would like obj1 and obj2 to return "equal" since they have the same properties/values.

Obviously obj1 === obj2 returns false, but I didn't know if there was a function already available I could use that would return true.

Community
  • 1
  • 1
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
  • Voted down. Question has been asked repeatedly (see comments above) – psema4 Dec 07 '12 at 19:57
  • This was specifically asking if there are any libraries that help with it – Jeff Storey Dec 07 '12 at 20:02
  • (Revised) True, but it really is a fine line. The answer you accepted was mentioned in 2/3 of the possible duplicates listed above and all 3 had answers based on library solutions. This was my first down vote; I seriously try to avoid them. In this case, looking at your stats I would've expected a search beforehand. After seeing the question I did a quick Google search to find a library-less version. The first two potential duplicates were the top 2 results returned from Google – psema4 Dec 07 '12 at 20:55
  • I did search (and found those questions), but I overlooked the underscore.js mentions. You are correct though, I should have read the search results more carefully. – Jeff Storey Dec 07 '12 at 21:01

1 Answers1

7

There is Underscore.js with the function isEqual() : http://underscorejs.org/#isEqual

koopajah
  • 23,792
  • 9
  • 78
  • 104