JS Built-ins
ObjectObject.getOwnPropertyDescriptorsintermediate

Object.getOwnPropertyDescriptors() β€” includes non-enumerable

πŸ“– Usage Example
// Inspect all property descriptors at once
const obj = { a: 1, b: 2 }
Object.getOwnPropertyDescriptors(obj)
// β†’ { a: { value: 1, writable: true, ... }, b: { value: 2, ... } }

Use Object.getOwnPropertyDescriptors() to get all property descriptors of an object, useful when doing a complete clone.

Object.getOwnPropertyDescriptors() β€” non-enumerable included

Unlike Object.keys or Object.entries, getOwnPropertyDescriptors includes non-enumerable properties.

Challenge: Implement countAllDescriptors(obj) that returns the total number of own properties (including non-enumerable).

// obj has 1 enumerable + 1 non-enumerable
countAllDescriptors(obj) // β†’ 2
πŸ’‘ Hints (1)
  • β€’ `Object.keys(Object.getOwnPropertyDescriptors(obj))` gives all own property names including non-enumerable.