JavaScript Statements The for Loop Loop (iterate over) an array to collect the car names: const cars = ["BMW", "Volvo", "Saab", "Ford"]; let text = ""; for (let i = 0; i < cars.length; i++) { text += cars[i] + ""; } document.getElementById...
a number How does a FOR loop start? for (i = 0; i <= 5; i++) How can you add a comment in a JavaScript? //This is a comment How to insert a comment that has more than one line? /*This comment has more than one line*/...
Click the button to loop through a block of code five times. Try it function myFunction() { var x = "", i; for (i=0; i<5; i++) { x = x + "The number is " + i + ""; } document.getElementById("demo").innerHTML = x; } ...
× Sign in Submit Answer »
You can list all Set elements (values) with afor..ofloop: Example // Create a Set constletters =newSet(["a","b","c"]); // List all Elements lettext =""; for(constx of letters) { text += x; } Try it Yourself »
The loop property sets or returns whether a video should start playing over again when it is finished.This property reflects the loop attribute.When present, it specifies that the video should start playing over again when it is finished.Browser ...
stringv-forloops through the string. Each character and its index can be picked out and used.Run Example » Iterablev-forcan also loop through iterables. Iterables are values that use the Iterable Protocol, like Map and Set.Run Example » ...
The for Loop Loop a NodeList and change the color of all p elements in the list: This is a p element This is a p element. This is a p element. const myNodelist = document.getElementsByTagName("P"); for (let i = 0; i < myNodelist.length; i++) {...
JavaScript For Of Loop The for of statement loops through the values of an iterable object. let language = "JavaScript"; let text = ""; for (let x of language) { text += x + ""; } document.getElementById("demo").innerHTML = text; ...
JavaScript Statements The for...of Loop Iterate (loop) over the characters of a string: let text1 = "JavaScript"; let text2 = ""; for (let x of text1) { text2 += x + " "; } document.getElementById("demo").innerHTML = text1 + "" + text2;...