HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Iterables are iterable objects (like Arrays)
The JavaScript for..of
statement loops
through the elements of an iterable object.
for (variable of iterable) {
// code block to be executed
}
Iterating is easy to understand.
It simply means looping over a sequence of elements.
Here are some easy examples:
You can use a for..of
loop to iterate over the elements of a string:
const name = "w3resource";
for (const x of name) {
// code block to be executed
}
You can use a for..of
loop to iterate over the elements of an Array:
const letters = ["a","b","c"];
for (const x of letters) {
// code block to be executed
}
You can learn more details about Iterables in the chapter JS Object Iterables.
You can use a for..of
loop to iterate over the elements of a Set:
const letters = new Set(["a","b","c"]);
for (const x of letters) {
// code block to be executed
}
Sets and Maps are covered in the next chapters.
You can use a for..of
loop to iterate over the elements of a Map:
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
for (const x of fruits) {
// code block to be executed
}