JAVASCRIPT FOR OF LOOP
The JavaScript for of loops are used to iterate through an object. We use for of loop to iterate arrays, strings, maps etc.
const bikes = ["Honda", "Yamaha", "Hayabusa"];
let txt = "";
for (let bike of bikes) {
txt += x + " ";
}
Live Demo!
Note that here the value of the next item to iterate is assigned to the variable declared in the for of loop which is different from the for in loop.
We can also apply for of loop on strings.
const exampleStr = "Sample Text";
let txt = "";
for (let a of exampleStr) {
txt += a + '<br/>';
}
Live Demo!