JS: Object.getOwnPropertyDescriptor ❌

By Xah Lee. Date: . Last updated: .
Object.getOwnPropertyDescriptor(obj, key)
  • Return the Property Descriptor of key of object obj.
  • If the property doesn't exist, return undefined.
  • If obj is not a object, it is first converted to a object type.

🟢 TIP: better is Reflect.getOwnPropertyDescriptor

// get the attributes of a property
console.log(Object.getOwnPropertyDescriptor({ "p": 4 }, "p"));
// { value: 4, writable: true, enumerable: true, configurable: true }

JavaScript. Define Properties and attributes.