Object.prototype.hasOwnProperty()【プロパティ有無】メソッド

メモ

  • 自身のプロパティの有無

構文

  • hasOwnProperty ( V )

  • V:プロパティ名

プロパティ有無 (true:あり / false:なし)

const point = { x:0, y:0 };
console.log(Object.prototype.hasOwnProperty.call(point, 'x'));
// 出力:true
console.log(Object.prototype.hasOwnProperty.call(point, 'y'));
// 出力:true
console.log(Object.prototype.hasOwnProperty.call(point, 'z'));
// 出力:false

関連