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: to throw error if argument is not a object, use Reflect.getOwnPropertyDescriptor

// get the attributes of a property
const jj = { "p": 4 };
const xx = Object.getOwnPropertyDescriptor(jj, "p");

  JSON.stringify(xx) ===

JavaScript, Define Properties

BUY ΣJS JavaScript in Depth