js loop array 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: js loop array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 3: loop array javascript
var colors = ['red', 'green', 'blue'];
colors.forEach((color, colorIndex) => {
console.log(colorIndex + ". " + color);
});
Example 4: js loop array
let colors = ['red', 'green', 'blue'];
for (const color of colors){
console.log(color);
}
Example 5: js loop array
Example 6: JS Loop Array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}