Use the following table as a desk reference for the various ways to obtain properties of objects and which properties each method returns.
Method/Operator/Loop | own | proto | enumerable | non-enumerable |
---|---|---|---|---|
for prop in obj |
✔️ | ✔️ | ✔️ | ❌ |
prop in obj |
✔️ | ✔️ | ✔️ | ✔️ |
obj.hasOwnProperty( prop ) |
✔️ | ❌ | ✔️ | ✔️ |
obj.propertyIsEnumerable( prop ) |
✔️ | ❌ | ✔️ | ❌ |
Object.assign( targetObj, ...obj ) |
✔️ | ❌ | ✔️ | ❌ |
Object.getOwnPropertyNames( obj ) |
✔️ | ❌ | ✔️ | ✔️ |
Object.keys( obj ) |
✔️ | ❌ | ✔️ | ❌ |