Object.hasOwn()

Returns true if the object has the specified property as its own (not inherited) property.

Since ES2022 Spec ↗

Syntax

Object.hasOwn(obj, prop)

Parameters

NameTypeRequiredDescription
obj object Yes The object to test.
prop string | symbol Yes The property name to check.

Returns

boolean — true if obj has prop as an own property; otherwise false.

Examples

console.log(Object.hasOwn({ a: 1 }, 'a'));
Output
true
console.log(Object.hasOwn({}, 'toString'));
Output
false

Notes

The recommended replacement for `obj.hasOwnProperty(prop)` - it works even when the object has no prototype or shadows hasOwnProperty. Does not see inherited properties.

Browser & runtime support

EnvironmentSince version
chrome 93
firefox 92
safari 15.4
edge 93
node 16.9

See also