JS Built-ins
ObjectObject.getOwnPropertyNamesbeginner

Object.getOwnPropertyNames() β€” empty object

πŸ“– Usage Example
// Get all own property names, including non-enumerable
const obj = { a: 1 }
Object.defineProperty(obj, 'hidden', { value: 2, enumerable: false })
Object.getOwnPropertyNames(obj)   // β†’ ['a', 'hidden']

Use Object.getOwnPropertyNames() to list all own properties including non-enumerable ones, unlike Object.keys().

Object.getOwnPropertyNames() on empty objects

Calling Object.getOwnPropertyNames on {} returns an empty array because there are no own properties.

Challenge: Implement isEmptyObject(obj) that returns true if Object.getOwnPropertyNames(obj) has length 0.

isEmptyObject({})         // β†’ true
isEmptyObject({ a: 1 })  // β†’ false
πŸ’‘ Hints (1)
  • β€’ Symbols are NOT returned by `getOwnPropertyNames` β€” use `getOwnPropertySymbols` for those.