hasOwnProperty() method determines if the specified object has the indicated property as its own property.
syntax ↴
hasOwnProperty(prop) ↴
prop The String name or Symbol of the property to test.
hasOwnProperty() method returns true if the specified object has the indicated property as its own property.
hasOwnProperty() method returns false if the property is inherited, or does not exist.
Objects created with Object.create(null) do not inherit from Object.prototype, making hasOwnProperty() inaccessible, so we can use Object.hasOwn() method instead.
Object.hasOwn() method is intended as a replacement for hasOwnProperty() method.
Array is an Object, so you can use hasOwnProperty() method to check whether an index exists ↴
const fruits = ['Apple', 'Banana', 'Mango', 'Pear']
fruits.hasOwnProperty(3) returns true (index 3 exists).
myObject.hasOwnProperty(property)