The Object getOwnPropertyDescriptor() method
Find out all about the JavaScript getOwnPropertyDescriptor() method of the Object object
THE AHA STACK MASTERCLASS
Launching May 27th
This method can be used to retrieve the descriptor of a specific property.
Usage:
const propertyDescriptor = Object.getOwnPropertyDescriptor(object, propertyName)
Example:
const dog = {}
Object.defineProperties(dog, {
breed: {
value: 'Siberian Husky'
}
})
Object.getOwnPropertyDescriptor(dog, 'breed')
/*
{
value: 'Siberian Husky',
writable: false,
enumerable: false,
configurable: false
}
*/
→ Get my JavaScript Beginner's Handbook
I wrote 20 books to help you become a better developer:
- Astro Handbook
- HTML Handbook
- Next.js Pages Router Handbook
- Alpine.js Handbook
- HTMX Handbook
- TypeScript Handbook
- React Handbook
- SQL Handbook
- Git Cheat Sheet
- Laravel Handbook
- Express Handbook
- Swift Handbook
- Go Handbook
- PHP Handbook
- Python Handbook
- Linux Commands Handbook
- C Handbook
- JavaScript Handbook
- CSS Handbook
- Node.js Handbook