Javascript array value is undefined ... how do I test for that
        Posted  
        
            by Ankur
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ankur
        
        
        
        Published on 2010-04-20T06:50:48Z
        Indexed on 
            2010/04/20
            6:53 UTC
        
        
        Read the original article
        Hit count: 230
        
I am trying to test to see whether a Javascript variable is undefined.
You will see that I am not expecting the value of predQuery[preId] to be 'undefined' if I don't first get an alert saying "its unbelievable". But I often do, so I am guessing that my statement
 predQuery[preId]=='undefined') 
is not matching the undefined elements properly.
if((predQuery.length < preId) || (predQuery[preId]=="") || (predQuery[preId]=='undefined')){
alert("its unbelievable");
alert(predQuery[preId]);
queryPreds[variables] = preId;
queryObjs[variables] = objId;
predQuery[preId] = variables;
}
else {
    alert(predQuery[preId]);
var predIndex = predQuery[preId];
queryPreds[predIndex] = preId;
queryObjs[predIndex] = objId;
}
I can add more code if needed.
© Stack Overflow or respective owner