For-2

 

In this example, We have an array of vehicles and implement the for loop on all vehicles. See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p id="sample"></p> <script> var vehicles = ["Alto", "Zen", "Audi", "Cruze"]; var i, length, text; for (i = 0, length = vehicles.length, text = ""; i < length; i++) { text += vehicles[i] + "<br>"; } document.getElementById("sample").innerHTML = text; </script> </body> </html>
Output