Skip to content
Tutorials Center
My learning

Topics

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.

JavaScript
obj.propertyIsEnumerable("name");

Try it

JS Enumerable and hidden properties

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Own only, and built-ins

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
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 returns false for 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 and Object.assign() copy enumerable symbols.
  • Array indexes are enumerable; length is not.
  • Reading the descriptor with Object.getOwnPropertyDescriptor() shows the same flag along with writable and configurable.
  • 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.