JavaScript Object.hasOwn() Method
The Object.hasOwn() static method checks whether an object has a property of its own, as opposed to an inherited one.
Description
The Object.hasOwn() static method returns true if the object has the property as its own property, not one inherited from its prototype. It's the recommended replacement for obj.hasOwnProperty(prop), which fails on objects created with Object.create(null) or that override that method. The in operator, by contrast, includes inherited properties.
It works on any object, including arrays, where it checks for indexes, and on objects whose hasOwnProperty has been overridden or removed. Passing null or undefined as the object throws a TypeError.
It's commonly used inside for...in loops to skip inherited properties, and when reading user-supplied keys from an object used as a dictionary, so that names like "toString" aren't mistaken for real entries. A Map avoids the issue entirely for dictionary-style data.
Syntax
Object.hasOwn(obj, prop)Parameters
- objThe object to work with.
- propThe property name or symbol to check.
Return Value
true if the object has the property directly (not inherited), otherwise false.
Example
Browser Support
The following information will show you the current browser support for the Object.hasOwn() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





