I have used Object.defineProperty
and enumerable: false
to define a few properties on a config object. There is however one place in my module where I would like to iterate over the non-enumerable properties as well as the enumerable ones. Is it possible to do this without keeping a list of property names elsewhere?
Enumerable properties are those properties whose internal enumerable flag is set to true, which is the default for properties created via simple assignment or via a property initializer. Properties defined via Object. defineProperty and such are not enumerable by default.
The for...in statement iterates over all enumerable properties of an object that are keyed by strings (ignoring ones keyed by Symbols), including inherited enumerable properties.
Objects can have properties that don't show up when iterated through the particular object using Object. keys() or for...in loop. Those type of properties are called as non-enumerable properties.
I guess you could use getOwnPropertyNames
which returns properties, enumerable or not.
From the docs:
Returns an array of all properties (enumerable or not) found directly upon a given object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With