Object

Object.hasOwn

Returns true if the specified object has the indicated property as its own property, intended as a replacement for Object.prototype.hasOwnProperty

Syntax

JavaScript
Object.hasOwn(obj, prop)

Parameters

ParameterTypeDescription
objobjectThe object to test
propstring | symbolThe property to test

Return Value

true if the object has the specified property as own property, false otherwise

Examples

Basic Usage
const obj = { name: 'Alice' };
console.log(Object.hasOwn(obj, 'name')); // true
console.log(Object.hasOwn(obj, 'toString')); // false
Practical Example
const map = Object.create(null);
map.key = 'value';
console.log(Object.hasOwn(map, 'key')); // true
Advanced Usage
const arr = [1, 2, 3];
console.log(Object.hasOwn(arr, '0')); // true
console.log(Object.hasOwn(arr, 'length')); // true

Understanding Object.hasOwn

The Object.hasOwn method in JavaScript returns true if the specified object has the indicated property as its own property, intended as a replacement for Object.prototype.hasOwnProperty. It belongs to the Object object and is one of the most widely used methods for working with object values in modern JavaScript and TypeScript applications.

The method signature is Object.hasOwn(obj, prop). It accepts 2 parameters: obj, prop. When called, it returns true if the object has the specified property as own property, false otherwise. Understanding when and how to use hasOwn() helps you write more expressive, readable code.

Common use cases for Object.hasOwn include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like object-keys, object-getownpropertynames, enabling you to chain operations together for complex data manipulation pipelines.

Supported in Chrome 93+, Firefox 92+, Safari 15.4+, Edge 93+, and Node.js 16.9+.

Browser Compatibility

Supported in Chrome 93+, Firefox 92+, Safari 15.4+, Edge 93+, and Node.js 16.9+.

Related Methods

More Object Methods

Other methods in the Object object

Related Tools

More Object Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.