Skip to content

JavaScript for of | Example code

  • by

JavaScript for statement creates a loop iterating over iterable objects. It could use in over iterable data structures such as Arrays, Strings, Maps, sets, and more:

for (variable of iterable) {
  statement
}

JavaScript for of Example

Simple example code.

<!DOCTYPE html>
<html>
<head>

  <script>
    const array1 = ['A', 'B', 'C'];

    for (const element of array1) {
      console.log(element);
    }
  </script>
</head>
<body>

</body>
</html>

Output:

JavaScript for of

Looping over a String

  <script>
    let language = "Tutorial";

    let text = "";
    for (let x of language) {
      text += x;
    }
    console.log(text)
  </script>

Output: Tutorial

Do comment if you have any doubts or suggestions on this JS for of statement topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading