JS Built-ins
← Object134 / 150
ObjectpropertyIsEnumerablebeginner

propertyIsEnumerable() β€” array indices

πŸ“– 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).

propertyIsEnumerable() β€” arrays

Array elements at numeric indices are own enumerable properties. propertyIsEnumerable('0') returns true for arrays.

However, the length property of an array is NOT enumerable.

Challenge: Verify array index enumerability.

πŸ’‘ Hints (1)
  • β€’ Array indices are strings in property lookup