Favorites

JavaScript Object.hasOwn() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Object.hasOwn()
JavaScript Object Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

const user = { name: 'Sam' };
console.log(Object.hasOwn(user, 'name'));
console.log(Object.hasOwn(user, 'toString'));
console.log('toString' in user);

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee