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.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.
The getOwnPropertyDescriptors()
method is supported by the following browsers:
Note: The
getOwnPropertyDescriptors()
method is not supported by Internet Explorer.
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)
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