While-2

 

JavaScript while loop on array of vehicles. var vehicles = ["Audi", "BMW", "Alto", "Swift"]; var i = 0; var text = ""; while (vehicles[i]) { text += vehicles[i] + "

"; i++; } 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 = ["Audi", "BMW", "Alto", "Swift"]; var i = 0; var text = ""; while (vehicles[i]) { text += vehicles[i] + "<br>"; i++; } document.getElementById("sample").innerHTML = text; </script> </body> </html>
Output