javascript Object getOwnPropertyDescriptors

getOwnPropertyDescriptors() method in object finds complete information of property and returns property descriptors.

This will be useful for a real shallow copy of an object cloning, Before ES8, the Object will be copied using Object.assign() which is not suitable for complex object graphs.

  • Syntax

Parameters and return type

  • Input is an object

  • return property descriptors of a given input object

  • Example

const myobject = {
const descriptors = Object.getOwnPropertyDescriptors(myobject);

And the output is

  id: {
    value: '1',
    writable: true,
    enumerable: true,
    configurable: true
  name: {
    value: 'Tom',
    writable: true,
    enumerable: true,
    configurable: true


console.log(; //true
console.log(; //1
console.log(; // undefined
console.log(; // undefined
console.log(; // true
console.log(; // true

Descriptors allowed for each property are as follows.

  • writable - the property allows to modify or not
  • value - the value of a property key
  • get - returns the getter function for the property if present, else undefined
  • set - setter function of the property, if present, else undefined
  • configurable - true, can be changed and will be deleted from an object, else false.
  • enumerable - if true, will be treated as enumerable property and shown during iteration

Important points:

  • It returns the own properties of an object
  • It does not consider properties from `Object. prototype inheritance

Support This will support in latest browsers To support in older browsers, enable the following plugins in your project.

  • polyfill
  • babel plugin