The hasOwnProperty() method checks whether an object has a property as its own (direct) property instead of being inherited from its prototype chain. It is available on all objects.
Using hasOwnProperty() allows you to filter out inherited properties in a for...in loop, ensuring that only direct properties are considered during iteration.
In scenarios where objects might have malicious properties injected via prototypes, hasOwnProperty() helps safeguard code by ensuring only direct properties are verified.
While useful, be cautious of the shadowing of hasOwnProperty() if an object includes a property with the same name, which can lead to unexpected results.
Collection
[
|
...
]