JS Built-ins
ObjectObject.getOwnPropertyNamesintermediate

Object.getOwnPropertyNames() β€” vs Object.keys

πŸ“– 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() vs Object.keys

Object.keys returns only enumerable properties. Object.getOwnPropertyNames returns all own string-keyed properties regardless of enumerability.

Challenge: Implement extraNames(obj) that returns property names that are in getOwnPropertyNames but NOT in Object.keys (i.e. non-enumerable names).

// obj has 'a' (enumerable) and '_h' (non-enumerable)
extraNames(obj) // β†’ ['_h']
πŸ’‘ Hints (1)
  • β€’ Filter `getOwnPropertyNames` result by removing items that also appear in `Object.keys`.