JavaScript Tutorial
JavaScript for...of loop (With Example)
Table of Contents
- Introduction
- What is a for...of loop in JavaScript?
- JavaScript for...of Loop Syntax
- Components of a For...of Loop in JavaScript
- Examples of JavaScript for...of Loop
- Advantages of For...of Loop
- Common Mistakes and Tips for Beginners
FAQs About for...in loop
The for...of loop iterates over values in an iterable, while the for...in loop iterates over keys or property names.
Not directly. Objects are not iterable, but you can use Object.entries, Object.keys, or Object.values to iterate over an object’s properties.
Yes, you can use break to exit the loop early or continue to skip to the next iteration.
Examples include arrays, strings, maps, sets, and any object that implements the iterable protocol.
It depends on the use case. The for...of loop is cleaner and more readable when iterating over values, but a traditional for loop provides more control over indices and iteration logic.