admin管理员组文章数量:1391951
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'])
本文标签: How to check if some field does not exist in JavaScriptStack Overflow
版权声明:本文标题:How to check if some field does not exist in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744694941a2620218.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论