for of loop 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: js loop
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 3: javascript for loop
for (var i; i < 10; i++) {
}
Example 4: javascript loop through array
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 5: for of js
let list = [4, 5, 6];
for (let i in list) {
console.log(i);
}
for (let i of list) {
console.log(i);
}
Example 6: for of loop javascript
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}