const object1 = {};
object1.property1 = 42;
console.log(object1.hasOwnProperty('property1'));
// expected output: true
console.log(object1.hasOwnProperty('toString'));
// expected output: false
console.log(object1.hasOwnProperty('hasOwnProperty'));
// expected output: false
判断对象是否有指定的属性:hasOwnProperty()
最新推荐文章于 2024-07-16 14:17:17 发布