Object.prototype.propertyIsEnumerable()
The least-used of the three inherited introspection methods. It answers a compound question, and because false covers two very different cases it is usually clearer to ask them separately.
Demo
The array cases show the two halves of the question. An index is an own enumerable property, so it is true — and that is why Object.keys lists it. length is a real own property of the array, but a non-enumerable one, so this returns false and Object.keys omits it. Note that the absent case and the inherited case both return false as well, which is the method weakness: a false answer cannot tell you whether the property is missing, inherited, or merely hidden.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| key | string | symbol | yes | The property key to test. Non-symbols are coerced to strings. |
Return value
boolean — True only if the key is BOTH an own property and enumerable. Inherited properties and non-enumerable ones both give false, with no way to tell which.
Common patterns
Object.hasOwn(o, k); Object.getOwnPropertyDescriptor(o, k)?.enumerable;
Object.keys(o).includes(k);
Object.prototype.propertyIsEnumerable.call(o, k);
Examples
Pitfalls
({}).propertyIsEnumerable("toString")
Object.hasOwn(o, k) && Object.getOwnPropertyDescriptor(o, k).enumerable
Object.create(null).propertyIsEnumerable("a")
Object.prototype.propertyIsEnumerable.call(o, "a")
Object.propertyIsEnumerable({a: 1}, "a")
Object.getOwnPropertyDescriptor(o, k)?.enumerable === true
When to use
- Rarely — a compact own-and-enumerable test in code you control
- Understanding why a property is missing from Object.keys
- You want to know if a property exists → Object.hasOwn
- You want the enumerability specifically → getOwnPropertyDescriptor
- You are listing keys → Object.keys already filters on this
- Untrusted objects → the method may be shadowed or missing
Notes
FAQ
It adds the enumerability requirement. A property defined with defineProperty, or a built-in like array length, is an own property — so hasOwnProperty is true — but it is not enumerable, so this returns false.
const o = {}; Object.defineProperty(o, "h", {value: 1}); Object.hasOwn(o, "h"); // true o.propertyIsEnumerable("h"); // false