0

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

Is there an easy way to compare 2 separate custom objects for all thier properties if they are the same ?

Example:

   var obj1 = {
    a: 1,
    b: 1,
    c: 1
    };

    var obj2 = {
    c: 1,
    b: 1,
    a: 1
    }
Community
  • 1
  • 1
mal200
  • 389
  • 7
  • 19

1 Answers1

0

Maybe something like this would work:

function compareObject(o1, o2){
    for(var p in o1){
        if(o1[p] !== o2[p]){
            return false;
        }
    }
    for(var p in o2){
        if(o1[p] !== o2[p]){
            return false;
        }
    }
    return true;
}
Denchr
  • 13
  • 3