JS: Object .prototype .propertyIsEnumerable 👎

By Xah Lee. Date: . Last updated: .
obj.propertyIsEnumerable(key)

Return true if key is a own key and Enumerable. Else, false.

console.assert({ dog: 4 }.propertyIsEnumerable("dog"));

🛑 warning: Object.prototype.propertyIsEnumerable won't work if a object has a property of that name. Better is to use Reflect.getOwnPropertyDescriptor.

// demo, problem of propertyIsEnumerable when a object has that property name.
const jj = {
 "dog": 4,
 "propertyIsEnumerable": () => "haha",
};
console.assert(
 jj.propertyIsEnumerable("dog") === "haha",
);