Object.getOwnPropertyDescriptor()

Returns the property descriptor for an own property of an object.

Since ES5 Spec ↗

Syntax

Object.getOwnPropertyDescriptor(obj, prop)

Parameters

NameTypeRequiredDescription
obj object Yes The object to inspect.
prop string | symbol Yes The name of the property whose descriptor is returned.

Returns

object | undefined — A descriptor object, or undefined if the property does not exist as an own property.

Examples

const o = { a: 1 };
console.log(Object.getOwnPropertyDescriptor(o, 'a'));
Output
{ value: 1, writable: true, enumerable: true, configurable: true }
console.log(Object.getOwnPropertyDescriptor({}, 'x'));
Output
undefined

Notes

Returns either a data descriptor (value/writable) or an accessor descriptor (get/set). Only inspects own properties, not inherited ones.

Browser & runtime support

EnvironmentSince version
chrome 5
firefox 4
safari 5
edge 12
node 0.10

See also