如果没有属性,如何检查对象 [英] How to check an object if it has no properties
本文介绍了如果没有属性,如何检查对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的JavaScript代码中的一个对象显示当我在Chrome的JS Debugger中检查它时它有无属性。我想申请if声明。我怎样才能做到这一点。因为
One of the object in my JavaScript code is showing that it has "No Properties" when I check it in JS Debugger of chrome. I want to apply if statement on it. How can I do that. Because
if (wsdl != null || wsdl != undefined || wsdl != NaN)
无法正常工作
is not working
推荐答案
当对象开启时这些
1:null
2:undefined
3:0
4:
它被称为假值
所以你可以这样做
when an object is on of these
1: null
2: undefined
3: 0
4: ""
it is called falsy value
so you can do this
if(!wsdl){
//do something
}
如果您不确定是否声明了wsdl,那么您可以这样做:
if you are not sure wsdl is declared so you can do this:
if(!window['wsdl']){
//do something
}
这篇关于如果没有属性,如何检查对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文