1.in运算符 (属性名 in 对象)
var obj={a:1};
"a" in obj//true
2.hasOwnProperty 只能识别对象自身的属性
var obj={a:1};
obj.hasOwnProperty("a")//true
obj.hasOwnProperty("toString")// false obj 本身没有toString属性
3.直接判断属性是否为undefined
if(obj.xxx == undefined){
}
1.in运算符 (属性名 in 对象)
var obj={a:1};
"a" in obj//true
2.hasOwnProperty 只能识别对象自身的属性
var obj={a:1};
obj.hasOwnProperty("a")//true
obj.hasOwnProperty("toString")// false obj 本身没有toString属性
3.直接判断属性是否为undefined
if(obj.xxx == undefined){
}
本文标题:js中判断对象是否存在某个属性
本文链接:https://www.haomeiwen.com/subject/bahhjktx.html
网友评论