- Detection property
in operator: if the inherited properties or attributes of its own object contains this property returns true
var o={x:1};
"x" in o;//true
"y" in o;//false
"toString" in o;true
hansOwnProperty (): detects whether the property is owned property of an object
var o={x:1}
o.hansOwnProperty("x");//true
o.hansOwnProperty("y");//false
o.hansOwnProperty("toString");//false
!==可以区分undefined和null
- Enumerated attribute
for / in loop can traverse the object can be enumerated attributes: its own property and inherit property
for(p in o){
if(!o.hanOwnProperty(p)) continue;//跳过继承属性
}
for(p in o){
if(typeof o[p] ==="function") continue;//跳过方法
}
- Get the name of the object properties
Object.keys()//返回一个数组,由对象中可枚举的属性名称组成,
Object.getOwnPropertyNames()//返回对象中所有自有属性的名称