Object.hasOwn()
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().
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 93 | 93 | 92 | 15.4 | 93 | 15.4 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
const obj = Object.create(null);
obj.key = 'value';
// obj.hasOwnProperty('key'); // Error!
Object.hasOwn(obj, 'key'); // true Live demo
Object.hasOwn Basics
Object that property has or confirm.hasOwnProperty. safeall alternative.
PreviewFullscreen
HasOwnProperty and. Comparison
also safeall to behavior. with Object.hasOwn is Object.create(null).
PreviewFullscreen
Use cases
-
Filtering own properties
Distinguish local data from inherited helpers when iterating or validating object input.
-
Safer guard conditions
Confirm a field exists directly on a record before reading or transforming it.
Cautions
- hasOwn only checks property ownership, not whether the value is meaningful, valid, or non-empty.
- Direct property checks do not replace schema validation for complex external data.
Accessibility
- If ownership checks influence visible labels or options, keep the resulting UI states explicit so users understand what is available.