JavaScript Object propertyIsEnumerable() Method (original) (raw)
Last Updated : 29 May, 2023
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