The Difference Between (for…in) and (for…of) in JavaScript
For...in is used to examine the properties of an object, including those inherited from its parent object. It provides the property keys, allowing you to access the corresponding values if necessary. However, the order of iteration may not match the order in which the properties were defined in the object.
For...of allows you to go through the elements of an iterable one at a time. It gives you the actual values directly, without concerning yourself with properties or keys. The order of iteration typically follows the order in which the elements were added for arrays, and for other iterables, it follows the defined order.
Front-End Web Developer | React | JavaScript | Nextjs
1 年https://medium.com/@bennythedev/the-difference-between-for-in-and-for-of-in-javascript-c50f40438af3