I have jQuery code like
for(var j in indivudvalbookdetails) {
if(indivudvalbookdetails[j]['status'] == "") {
...
}
}
Now there might be some items in the loop where status field won't exists, if there are such items the code in the if condition should work.
I have jQuery code like
for(var j in indivudvalbookdetails) {
if(indivudvalbookdetails[j]['status'] == "") {
...
}
}
Now there might be some items in the loop where status field won't exists, if there are such items the code in the if condition should work.
Share Improve this question edited Dec 17, 2021 at 23:52 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Nov 5, 2017 at 9:59 NidaNida 1,7023 gold badges36 silver badges75 bronze badges 3-
Instead of the empty character, check for
undefined
, and use strict parison operator. – Teemu Commented Nov 5, 2017 at 10:04 - can u show me in the code – Nida Commented Nov 5, 2017 at 10:08
- This is pure javascript, theres no jquery involved here. – Jonas Wilms Commented Nov 5, 2017 at 10:29
4 Answers
Reset to default 2Try this:
var myElement = indivudvalbookdetails[j]['status'];
if (typeof(myElement) != 'undefined' && myElement != null)
{
// exists.
}
You can also try with JQuery like:
if ($('#elementId').length > 0) {
// exists.
}
Just check if its undefined:
if(typeof indivudvalbookdetails[j]['status'] === "undefined") { ...
Your code is paring your variable to an empty string. But if this variable is not defined, it can’t pare it, so you can do :
if(indivudvalbookdetails[j]['status'] == undefined)
If the « status » var is defined but just empty you can do
if(indivudvalbookdetails[j]['status'] == null)
You check like this
if(!indivudvalbookdetails[j]['status'])