Object

Object.getOwnPropertyDescriptor

Returns a property descriptor for an own property of a given object

Syntax

JavaScript
Object.getOwnPropertyDescriptor(obj, prop)

Parameters

ParameterTypeDescription
objobjectThe object to look up
propstring | symbolName of the property

Return Value

A property descriptor, or undefined if the property doesn't exist

Examples

Basic Usage
const obj = { name: 'Alice' };
const desc = Object.getOwnPropertyDescriptor(obj, 'name');
console.log(desc);
// { value: 'Alice', writable: true, enumerable: true, configurable: true }
Practical Example
const frozen = Object.freeze({ x: 1 });
const desc = Object.getOwnPropertyDescriptor(frozen, 'x');
console.log(desc?.writable); // false
Advanced Usage
const arr = [1, 2, 3];
const desc = Object.getOwnPropertyDescriptor(arr, 'length');
console.log(desc?.writable); // true

Understanding Object.getOwnPropertyDescriptor

The Object.getOwnPropertyDescriptor method in JavaScript returns a property descriptor for an own property of a given object. 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.getOwnPropertyDescriptor(obj, prop). It accepts 2 parameters: obj, prop. When called, it returns a property descriptor, or undefined if the property doesn't exist. Understanding when and how to use getOwnPropertyDescriptor() helps you write more expressive, readable code.

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

Browser support for Object.getOwnPropertyDescriptor is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

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.