What is Object.getOwnPropertyDescriptors() in Javascript?

The Object.getOwnPropertyDescriptors() method returns all the property descriptors of the properties of an object. getOwnPropertyDescriptors() is declared as follows:

Object.getOwnPropertyDescriptors(obj)
  • obj: The object whose property descriptors are required.

Return value

The getOwnPropertyDescriptors() method returns an object that contains all the property descriptors of the object obj.

Note: If an object has no properties, the getOwnPropertyDescriptors() method returns an empty object.

Browser compatibility

The getOwnPropertyDescriptors() method is supported by the following browsers:

  • Edge 15
  • Firefox 50
  • Google Chrome 54
  • Opera 41
  • Safari 10

Note: The getOwnPropertyDescriptors() method is not supported by Internet Explorer.

Example

Consider the code snippet below, which demonstrates the use of the getOwnPropertyDescriptors() method:

var obj = { property1: 'foo1',
property2: 'foo2',
property3: 'foo3'
}
var objDescriptors = Object.getOwnPropertyDescriptors(obj)
console.log("obj has properties: ", objDescriptors)

Explanation

An object obj is declared in line 1 with three properties, property1, property2, and property3. The getOwnPropertyDescriptors() method is called on obj in line 6. The method returns an object that contains the property descriptors of obj. This object is assigned to objDescriptors in line 6.

Free Resources

HowDev By Educative. Copyright ©2025 Educative, Inc. All rights reserved