Object.getOwnPropertyDescriptor()

ES5+

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

Syntax

Object.getOwnPropertyDescriptor(obj, prop)

Parameters

obj Object

The object to look for the property on

prop string

The name of the property whose descriptor should be retrieved

Return Value

Object | undefined

A property descriptor of the given property, or undefined if it does not exist

Examples

JavaScript
const obj = { name: 'John' };
const desc = Object.getOwnPropertyDescriptor(obj, 'name');
console.log(desc.value);
console.log(desc.writable);
Output:
// 'John' true

Related Methods