The Difference Between "for...in" and "for...of" in JavaScript
There are two very similar statements in JavaScript: for...in
and for...of
. And while they can be easily confused, they're actually quite different. In this guide, we'll cover the usage of both statements with multiple examples of each.
In short, for...in
iterates over the enumerable properties of an object, while for...of
iterates over "iterable collections". There's more nuance, but you can generally think of for...in
as iterating over object properties and for...of
as iterating over iterable values. Continue reading for further explanation and examples of each.