Object.prototype.hasOwnProperty()
hasOwnProperty() 方法会返回一个布尔值,指示对象自身属性中是否具有指定的属性(也就是,是否有指定的键)。
a = [1, 2, 3]
for(key in a) {
console.log(key)
console.log(a.hasOwnProperty(key))
}
console.log('###################')
b = {
c: 1,
d: 2,
}
for(key in b) {
console.log(key)
console.log(b.hasOwnProperty(key))
}
![](https://img.haomeiwen.com/i22548971/50c2c57a59977e28.png)
网友评论