LoginSignup
0
0

More than 1 year has passed since last update.

【JavaScript】 オブジェクトが指定されたプロパティを自身のプロパティとして持っているかどうか確認するには?

Posted at

オブジェクトが指定されたプロパティを自身のプロパティとして持っているかどうか確認するには?

こちら、ご参考下さい!

index.js
 //構文
 obj.hasOwnProperty(prop)

 //example
 const object1 = {};
 object1.property1 = 42;

 console.log(object1.hasOwnProperty('property1')); // Expected output: true

 console.log(object1.hasOwnProperty('toString')); // Expected output: false

 console.log(object1.hasOwnProperty('hasOwnProperty')); // Expected output: false

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0