Another difference between the two loops, which nobody has mentioned before:
Destructuring
for...in
is deprecated. Usefor...of
instead.
So if we want to use destructuring in a loop, for get both index and value of each array element, we should to use the for...of
loop with the Array method entries()
:
for (const [idx, el] of arr.entries()) {
console.log( idx + ': ' + el );
}