JS Built-ins
← Object131 / 150
ObjectpropertyIsEnumerablebeginner

propertyIsEnumerable() β€” basics

πŸ“– Usage Example
// Check if a property shows up in for...in loops
const obj = { a: 1 }
obj.propertyIsEnumerable('a')   // β†’ true
Object.defineProperty(obj, 'b', { value: 2, enumerable: false })
obj.propertyIsEnumerable('b')   // β†’ false

Use propertyIsEnumerable() to check whether a specific own property will appear during enumeration (e.g., for...in or Object.keys).

Object.prototype.propertyIsEnumerable()

obj.propertyIsEnumerable(key) returns true if the specified property is an own property AND is enumerable.

Challenge: Implement isEnumerable(obj, key) that returns whether the property is own and enumerable.

πŸ’‘ Hints (1)
  • β€’ propertyIsEnumerable checks both ownership AND enumerability