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.log({ "p": 4 }.propertyIsEnumerable("p"));

🛑 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 = { "pp": 4, "propertyIsEnumerable": ((x) => x + " haha") };
console.assert(jj.propertyIsEnumerable("pp") === "pp haha");

JavaScript. Define Properties and attributes.