loop element javascript code example
Example 1: js for loop
var i; //defines i
for (i = 0; i < 5; i++) { //starts loop
console.log("The Number Is: " + i); //What ever you want
}; //ends loop
//Or:
console.log("The Number Is: " + 0);
console.log("The Number Is: " + 1);
console.log("The Number Is: " + 2);
console.log("The Number Is: " + 3);
console.log("The Number Is: " + 4);
//They do the same thing!
//Hope I helped!
Example 2: for in loop javascript
let array = [1,2,3,4,5,6,7,8,9,10];
// our array that we will use the for loop on
for (let i = 0; i < array.length; i++) {
// this loop will console log the element at array[i] starting at 0
// and will continue looping for i < array.length
console.log(array[i]);
// after each loop i will increase by 1
}
// this will console log
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10