Possible Duplicate:
How do you determine equality for two JavaScript objects?
Why does [1,[2,3]] == [1,[2,3]]
evaluate to false?
Also, why does this happen:
var g = { a:1, b:2, c:3 };
g == { a:1, b:2, c:3 }; // false!!
Possible Duplicate:
How do you determine equality for two JavaScript objects?
Why does [1,[2,3]] == [1,[2,3]]
evaluate to false?
Also, why does this happen:
var g = { a:1, b:2, c:3 };
g == { a:1, b:2, c:3 }; // false!!
[]
is a shortcut to make an array literal instead of calling new Array()
and then populating it. It's a similar story for {}
. In your example, you are actually comparing by reference instead of by value. Two objects constructed with the new
operator point to different locations in memory, and when you use the ==
operator you are actually saying "do these objects point to the same location in memory?". To do a by-value comparison like you're expecting, you would need to iterate through the members of each array/object you're comparing and compare each value one-by-one.