美文网首页
Object.prototype.hasOwnProperty(

Object.prototype.hasOwnProperty(

作者: hszz | 来源:发表于2021-11-05 00:06 被阅读0次

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))
}
image.png

相关文章

网友评论

      本文标题:Object.prototype.hasOwnProperty(

      本文链接:https://www.haomeiwen.com/subject/yadlzltx.html