C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.getOwnPropertyDescriptors() MethodThe Object.getOwnPropertyDescriptors() method returns all own property descriptors of a given object. The difference between getOwnPropertyDescriptors() and getOwnPropertyDescriptor() method is that getOwnPropertyDescriptors() method ignores symbolic properties. Syntax:
Object.getOwnPropertyDescriptors(obj) Parameter
obj: It is the object for which to get all own property descriptors. Return:This method returns an object which contains all own property descriptors of an object. This method might return an empty object if there are no properties. Browser Support:
Example 1
const object1 = {
property1: 103
};
const descriptors1 = Object.getOwnPropertyDescriptors(object1);
console.log(descriptors1.property1.writable);
console.log(descriptors1.property1.value);
Output: 103 Example 2
const object1 = {
property1: 22
};
const descriptors1 = Object.getOwnPropertyDescriptors(object1);
console.log(descriptors1.property1.value);
console.log(descriptors1.property1);
console.log(descriptors1.property1.writable);
Output: [object Object] {
configurable: true,
enumerable: true,
value: 22,
writable: true
}
true
Example 3
const object1 = {
property1: 42
};
const object2 = {
property2: 23
};
const descriptors1 = Object.getOwnPropertyDescriptors(object1);
const descriptors2 = Object.getOwnPropertyDescriptors(object2);
console.log(descriptors1.property1.writable);
console.log(descriptors1.property1.value,descriptors2.property2.value);
Output: true 42 23
Next TopicJavaScript Objects
|