hasOwnProperty() 方法会返回一个布尔值,指示对象自身属性中是否具有指定的属性(也就是,是否有指定的键)。

    1. const object1 = {};
    2. object1.property1 = 42;
    3. console.log(object1.hasOwnProperty('property1'));
    4. // expected output: true
    5. console.log(object1.hasOwnProperty('toString'));
    6. // expected output: false
    7. console.log(object1.hasOwnProperty('hasOwnProperty'));
    8. // expected output: false