JS: Object .getOwnPropertyDescriptor 👎
Object.getOwnPropertyDescriptor
Object.getOwnPropertyDescriptor(obj, key)-
- Return the Property Descriptor of key of object obj.
- If the property doesn't exist, return undefined.
- 🛑 warning: if obj is not an object, it is first converted to an object type.
🟢 tip: better is Reflect.getOwnPropertyDescriptor
// get the attributes of property console.log( Object.getOwnPropertyDescriptor({ dog: 4 }, "dog"), ); // { value: 4, writable: true, enumerable: true, configurable: true }
Edge case. arg is not an object
// when the arg is not an object console.log( Object.getOwnPropertyDescriptor(8, "dog"), ); // undefined