Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Object propertyIsEnumerable() Method

JavaScript Object propertyIsEnumerable() Method

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

Syntax:

obj.propertyIsEnumerable(prop)

Parameters: This method accepts a single parameter.

  • prop: The name of the property to test.

Return value: This method returns a boolean value.

Example 1: This example shows the basic use of the JavaScript Object.prototype.propertyIsEnumerable() method.

javascript




<script>
    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'));
</script>


Output:

true
true
false

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

javascript




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


Output:

true
false
false
false

We have a complete list of Javascript Object Methods, to check those please go through the Javascript Object Complete Reference article.

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer
  • Opera 4 and above
  • Safari 3 and above
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments