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!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
[]is a shortcut to make an array literal instead of callingnew 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 thenewoperator 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.