Search⌘ K
AI Features

Object.getOwnPropertyDescriptors

Explore how Object.getOwnPropertyDescriptors retrieves all property descriptors for an object, including value, writable, get, set, configurable, and enumerable attributes. Understand its use for shallow copying objects and handling symbol keys, enhancing your grasp of ES2017 object manipulation.

We'll cover the following...

Object.getOwnPropertyDescriptors returns all property descriptors of its first argument:

Node.js
let player = {
cards: [ 'Ah', 'Qc' ],
chips: 1000
};
let descriptors =
Object.getOwnPropertyDescriptors( player );
console.log( descriptors );
console.log();
console.log( descriptors.cards );

Object.getOwnPropertyDescriptors returns all property descriptors in an object with the same keys as the keys of the original object. The following four property descriptors are returned (source: developer.mozilla.com):

  • value: the value
...