JS判断对象是否包含某个属性
1使用hasOwnProperty()判断
hasOwnProperty方法的参数就是要判断的属性名称,当对象的属性存在时返回true,否则返回false。
varobj={name:'jack'};
JS判断对象是否包含某个属性
1使用hasOwnProperty()判断
hasOwnProperty方法的参数就是要判断的属性名称,当对象的属性存在时返回true,否则返回false。
varobj={name:'jack'};
console」og(('name'))//-->trueconsole」og(('toString'))〃-->false
2•使用undefined判断
console」og(!==undefined)//trueconsole」og(!==undefined)//falseconsole」og(!==undefined)//true'
JS判断对象是否包含某个属性 来自淘豆网m.daumloan.com转载请标明出处.