Reputation: 33655
How do you detect an undefined item in jQuery in an 'if statement' I have tried something like below without any success so far.
success: function(data){
if(typeof data.DATA[0].RECIPIENTID = 'undefined'){
// do nothing
}
else {
//else get value
console.log(data.DATA[0].RECIPIENTID);
}
console.log(data);
}
});
Upvotes: 1
Views: 148
Reputation: 918
undefined does not need quotes ''
if(RECIPIENTID === undefined){
// do nothing
alert("undefined");
}
Upvotes: 1
Reputation: 359966
=
is an assigment operator in JavaScript. Use ===
, not =
.
if(typeof data.DATA[0].RECIPIENTID === 'undefined'){
// ...
}
// ...
See also Which equals operator (== vs ===) should be used in JavaScript comparisons?
Upvotes: 9