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.

New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved