JavaScript Non enumerable property


Example

5

We can avoid a property from showing up in for (... in ...) loops

The enumerable property of the property descriptor tells whether that property will be enumerated while looping through the object's properties.

var obj = { };

Object.defineProperty(obj, "foo", { value: 'show', enumerable: true });
Object.defineProperty(obj, "bar", { value: 'hide', enumerable: false });

for (var prop in obj) {
    console.log(obj[prop]);
}

Console output

show