Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
The Object.hasOwn() static method returns true if the specified object has the indicated property as its own property. If the property is inherited, or does not exist, the method returns false.
Note: Object.hasOwn() is intended as a replacement for Object.prototype.hasOwnProperty().
The JavaScript object instance to test.
propThe String name or Symbol of the property to test.
true if the specified object has directly defined the specified property. Otherwise false
The Object.hasOwn() method returns true if the specified property is a direct property of the object — even if the property value is null or undefined. The method returns false if the property is inherited, or has not been declared at all. Unlike the in operator, this method does not check for the specified property in the object's prototype chain.
It is recommended over Object.prototype.hasOwnProperty() because it works for null-prototype objects and with objects that have overridden the inherited hasOwnProperty() method. While it is possible to workaround these problems by accessing Object.prototype.hasOwnProperty() on another object (like Object.prototype.hasOwnProperty.call(obj, prop), Object.hasOwn() is more intuitive and concise.
The following code shows how to determine whether the example object contains a property named prop.
The following example differentiates between direct properties and properties inherited through the prototype chain:
To iterate over the enumerable properties of an object, you should use:
But if you need to use for...in, you can use Object.hasOwn() to skip the inherited properties:
The elements of an Array are defined as direct properties, so you can use hasOwn() method to check whether a particular index exists:
This section demonstrates that Object.hasOwn() is immune to the problems that affect hasOwnProperty(). Firstly, it can be used with objects that have re-implemented hasOwnProperty(). In the example below, the re-implemented hasOwnProperty() method reports false for every property, but the behavior of Object.hasOwn() remains unaffected:
It can also be used with null-prototype objects. These do not inherit from Object.prototype, and so hasOwnProperty() is inaccessible.
| ECMAScript® 2027 Language Specification # sec-object.hasown |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 20, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.