Object.hasOwn() static method determines if the specified object has the indicated property as its own property.
syntax ↴
Object.hasOwn(obj, prop) ↴
obj The JavaScript object instance to test.
prop The String name or Symbol of the property to test.
Object.hasOwn() method returns true if the specified object has the indicated property as its own property.
Object.hasOwn() method returns false if the property is inherited, or does not exist.
Object.hasOwn() method works for objects created by using Object.create(null) and for objects that have overridden the inherited hasOwnProperty() method.
Object.hasOwn() method is intended as a replacement for hasOwnProperty() method.
Array is an Object, so you can use hasOwn() method to check whether an index exists ↴
const fruits = ['Apple', 'Banana', 'Mango', 'Pear']
Object.hasOwn(fruits, 3) returns true (index 3 exists).
Object.hasOwn(myObject, property)