JavaScript for of statement | Example code

JavaScript for…of iterates over the values of an iterable object. Examples of iterable objects are arrays, strings, and NodeLists.


Example of JavaScript for of

Let’s take a look at some HTML examples of using the for…of loop.

Iterating over arrays

Easy Loop through the values of an array using for..of:-


JavaScript for of statement array

Iterating over strings

The following example uses the for...of loop to iterate over characters of a string.


JavaScript for of statement strings

Do comment if you have any suggestions or doubts on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.