Javascript: Object Equivalence
Posted: Thu Aug 17, 2006 9:56 am
Is it possible to easily check if two different objects are identical? The following code refuses to return true, so unless there's a special technique I'm unaware of, it's not going to be simple:
If I have to loop through properties, so be it, but I'd really prefer something like this, that's automatic. Thanks.
Code: Select all
var A = {one: 'bob', two: 'six', th3: [1,2,3]};
var B = {one: 'bob', two: 'six', th3: [1,2,3]};
if(A == B || A === B) return true;
if(eval(A) == eval(B) || eval(A) === eval(B)) return true;
return false;