Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Object.prototype.propertyIsEnumerable() method

  • Last Updated : 28 Sep, 2021

The method propertyIsEnumerable() returns a Boolean indicating whether the specified property is enumerable and is the object’s own property. If the object doesn’t have the specified property, this method returns false.

Syntax:

obj.propertyIsEnumerable(prop)
  • prop: The name of the property to test.

Return value: Boolean.

Example 1:

javascript




const obj = {};
const arr = [];
obj.property = 42;
arr[0] = 42;
 
console.log(obj.propertyIsEnumerable('property'));
console.log(arr.propertyIsEnumerable(0));
console.log(arr.propertyIsEnumerable('length'));

Output:

true
true
false

Example 2: The following example illustrates the enumerability of user-defined vs. built-in properties:

javascript




let a = ['is enumerable'];
 
console.log(a.propertyIsEnumerable(0));        
console.log(a.propertyIsEnumerable('length'));  
 
console.log(Math.propertyIsEnumerable('random')); 
console.log(this.propertyIsEnumerable('Math'));    

Output:

true
false
false
false

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer
  • Opera 4 and above
  • Safari 3 and above

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!