loop through functions javascript code example
Example 1: js for loop
var i;
for (i = 0; i < 5; i++) {
console.log("The Number Is: " + i);
};
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);
Example 2: javascript iterate through for loop
var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
console.log(myStringArray[i]);
}
Example 3: iterate array in javascrpt
let array = [ 1, 2, 3, 4 ];
for( let element of array ) {
console.log(element);
}
Example 4: looping in javascript
for (initialization; test condition; iteration statement) {
Statement(s) to be executed if test condition is true
}