Non enumerable property
suggest changeWe can keep a property from showing up in for (... in ...) loops.
The enumerable attribute of the property descriptor controls whether that property is visited. for...in walks enumerable properties of the object and of its prototype chain, and it skips non-enumerable properties.
const obj = { };
Object.defineProperty(obj, "foo", { value: 'show', enumerable: true });
Object.defineProperty(obj, "bar", { value: 'hide', enumerable: false });
for (const prop in obj) {
console.log(obj[prop]);
}
Console output
show
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents