The object on which to check if the property is enumerable
The property name or symbol to check
A Boolean indicating whether the specified property is enumerable
const obj = {};
const arr = [];
obj.property1 = 42;
// Custom property is enumerable
console.log(objPropertyIsEnumerable(obj, "property1")); // true
// Array length is not enumerable
console.log(objPropertyIsEnumerable(arr, "length")); // false
// Checking a property that doesn't exist returns false
console.log(objPropertyIsEnumerable(obj, "nonExistent")); // false
The
objPropertyIsEnumerable()
method returns a Boolean indicating whether the specified property is enumerable and is a property of the specified object. This method is similar to the nativeObject.prototype.propertyIsEnumerable()
method, but it is a standalone function that can be used without needing to call it on the object itself. This will attempt to use the native method if it exists and is callable, otherwise it will use a helper implementation that will check for the property on the instance provided, if that instance has apropertyIsEnumerable
method it will be called, otherwise it will check whether the property is available on the instance and if it is enumerable.