In general:
Use for
...in
loops to loop over the keys of an object.
Use for
...of
loops to iterate over an array or string.
The two loop types: for...in and for...of behave differently in javascript. Both loops can be used with Arrays and Strings - but only for
...of
loops iterate over the values in order. for
...in
loops actually loop over the enumerable properties of an object. For an array, that means that a for
...in
loop iterates over the indices of the array - and order is not guaranteed. So use for
...of
for arrays or strings, and for
...in
for objects.