for of loop javascript 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: 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 3: for of loop javascript
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
Example 4: for?of loop
const iterable = [10, 20, 30];
for (const value of iterable) {
console.log(value);
}
Example 5: javascript for of
const numbers = [1,2,3,4];
for(const item of numbers){
console.log(item);
}
Example 6: js for
for (let step = 0; step < 5; step++) {
console.log(step);
}
0
1
2
3
4