hasOwnProperty方法可以用来检查一个对象是否包含特定属性(自身属性),它的使用方法如下:
const obj = {
name: 'Alice',
age: 30
};
console.log(obj.hasOwnProperty('name')); // 输出true,因为obj对象有一个名为'name'的属性
console.log(obj.hasOwnProperty('gender')); // 输出false,因为obj对象没有名为'gender'的属性
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:formatnumber在JavaScript中怎么使用