温馨提示×

hasOwnProperty有没有替代方法

小樊
127
2024-06-19 16:55:01
栏目: 深度学习
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

有,可以使用Object.prototype.hasOwnProperty.call()方法来替代hasOwnProperty方法。例如:

var obj = {
  key: 'value'
};

if (Object.prototype.hasOwnProperty.call(obj, 'key')) {
  console.log('The key exists in the object.');
} else {
  console.log('The key does not exist in the object.');
}

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:jsIndexOf有没有替代方法

0