Many style guides and linters recommend against the use of for…in when it comes to iterating over an object. This is because it iterates over the entire prototype chain, which is rarely what you want. However, for…in is often the only practical way to get a listing of an object’s property names and values.
Luckily, since ES6 introduced the hasOwnProperty function, you can now use it to check whether or not an object has a certain property. This method works by comparing the key of the property to the name of the object itself. Then it returns a boolean value indicating whether or not the object actually owns the property. This allows you to skip over properties that are inherited from its prototypes and only iterate over its own enumerable properties. It is recommended to use this method instead of a for…in loop in all cases, and to use it with the destructuring assignment syntax to unpack the property values into distinct variables. This will make it easier to read and write the code.