Junior JavaScript

What is the difference between for, for...of, and for...in?

Loop Used For Iterates Over

for Traditional

loop

Index/count

for...

Arrays/iterable

Values

for...

Objects Keys

Example:

for (let i in obj) console.log(i); // keys

for (let v of arr) console.log(v); // values

More from JavaScript Tutorial

All questions for this course