JavaScript Reference ยท Object
Object.prototype.propertyIsEnumerable()
Reference for JavaScript propertyIsEnumerable(): check whether a property is own and enumerable, and how it affects loops, keys() and spread.
propertyIsEnumerable() tells you whether a property is both an own property of the object and enumerable. Enumerable properties are the ones that show up in for...in loops, Object.keys(), Object.entries(), spread ({ ...obj }) and JSON.stringify().
Properties created by assignment or object literals are enumerable. Built-in members such as an array's length and methods on class prototypes are not.
obj.propertyIsEnumerable("name");
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
obj.propertyIsEnumerable(prop)
| Name | Description |
|---|---|
prop |
The property name (string or symbol) to test. Other values are converted to a key. |
Return value: true if the property exists directly on the object and its enumerable attribute is true; otherwise false.
Exceptions: a TypeError if the method is called on null or undefined. Objects without a prototype (Object.create(null)) do not have the method at all.
Usage notes
- Own properties only. Unlike
for...in, which also visits inherited enumerable keys, this method returnsfalsefor anything found only on the prototype chain, even if that property is enumerable. - Missing means false. It cannot tell "absent" from "present but hidden". Use
Object.hasOwn()to test existence. - Symbols count. A symbol property can be enumerable, yet
Object.keys()skips symbols. Spread andObject.assign()copy enumerable symbols. - Array indexes are enumerable;
lengthis not. - Reading the descriptor with
Object.getOwnPropertyDescriptor()shows the same flag along withwritableandconfigurable. - Rarely needed directly. Mostly used in libraries that copy objects or in teaching examples.
- Null-prototype objects: use
Object.prototype.propertyIsEnumerable.call(obj, key).
Browser support
propertyIsEnumerable() is available in every browser and JavaScript runtime.