Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.getOwnPropertyDescriptors — descriptors of own properties

For an ordinary object, Object.getOwnPropertyDescriptors returns descriptors for all its own properties, including non-enumerable and Symbol-keyed properties. Use it to inspect attributes or copy properties without turning accessors into values.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Object.getOwnPropertyDescriptors(obj)

Object.getOwnPropertyDescriptors(obj) returns a new ordinary object. The method gets the list of own property keys from obj and includes a descriptor for each listed key if obj reports one. It handles both string and Symbol keys, including those of non-enumerable properties; inherited properties are excluded.

A data property descriptor contains value, writable, enumerable, and configurable. An accessor descriptor contains get and set instead of value and writable; a missing function is represented by undefined. Reading an ordinary object's descriptors does not invoke its getters. For a Proxy, however, traps may run and exceptions may occur. The result can also be incomplete without throwing: the ownKeys trap can omit the key of a configurable own property of an extensible target, even if the proxy still reports an own property descriptor for that key. The method then leaves that descriptor out of the result.

For an ordinary object, the pattern Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj)) creates a shallow copy with the same prototype and own-property attributes. Unlike Object.assign, it preserves accessors and non-enumerable properties. Nested objects remain shared; this is not a general cloning technique for objects that depend on internal slots, such as Map.

null and undefined cause a TypeError; other primitive values are wrapped as objects. The method belongs to ECMAScript 2017, not Web APIs. Support in the target browser needs separate checking—availability in Node 24 does not prove it.

Examples

let reads = 0;
const source = Object.create(null);
Object.defineProperties(source, {
  hidden: { value: 7, enumerable: false },
  doubled: {
    get() { reads += 1; return this.hidden * 2; },
    enumerable: true
  }
});
const descriptors = Object.getOwnPropertyDescriptors(source);
const copy = Object.create(Object.getPrototypeOf(source), descriptors);
console.log(reads);
console.log(descriptors.hidden.value, descriptors.hidden.enumerable);
console.log(typeof descriptors.doubled.get);
console.log(copy.doubled, reads);
console.log(Object.getPrototypeOf(copy) === null);

Result

0
7 false
function
14 1
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources