Monday, 19 March 2018

equals - javascript library for comparing objects











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.



Answer



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


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...