Looping Over Arrays with the JavaScript For Of Loop

The for of statement loops through the values of any iterable object.

It lets you loop over iterable data structures such as Arrays, Strings, Maps, NodeLists, and more

In the example below, the array of cars can be looped over and output the results in a list.

Here is the code:
<p>Some of my favorite cars are:<br>
<span id="demo"></span></p>
<script>
    const cars = ["BMW", "Volvo", "Mercedes", "Jaguar"];
    let favCars = "";
    for (let x of cars) 
    {favCars += x + "<br>";  }
    document.getElementById("demo").innerHTML = favCars;
</script>
      
Here is the results:

Some of my favorite cars are: