Possible Duplicate:
JavaScript compare arrays
var x = [""]
if (x === [""]) { alert("True!") }
else { alert("False!") }
For some reason, this alerts False. I cannot seem to figure out why. What can I do to make this alert True?
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.
Compare values not whole arrays
…as they’re objects and you’re working with implicit references here. One object is stored in your
xvaliable which you’re trying to compare (by reference) with an in-place created object (array with an empty string element). These are two objects each having it’s own reference hence not equal.I’ve changed your example to do what you’re after while also providing the possibility to have an arbitrary number of empty strings in an array:
This will return True! for any arrays like: