阅读量:160
hasOwnProperty方法可以用来检查一个对象是否包含特定属性(自身属性),它的使用方法如下:
const obj = {
name: 'Alice',
age: 30
};
console.log(obj.hasOwnProperty('name')); // 输出true,因为obj对象有一个名为'name'的属性
console.log(obj.hasOwnProperty('gender')); // 输出false,因为obj对象没有名为'gender'的属性