for loops in JS code example
Example 1: javascript for loop
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: 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 3: javascript loop
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item);
});
Example 4: loop javascript
for(let i = 0; i < arr.length; i++){
}
Example 5: javascript loop statement
do
{
code to be executed
}
while (condition)
Example 6: for of loop syntax javascript
for (let step = 0; step < 5; step++) {
console.log('Walking east one step');
}