javascript forof code example
Example 1: javascipr for of
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
Example 2: for of loop syntax javascript
for (let step = 0; step < 5; step++) {
console.log('Walking east one step');
}
Example 3: how to use for of in javascript
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
Example 4: mdn for..of
function* fibonacci() {
let [prev, curr] = [0, 1];
while (true) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
for (const n of fibonacci()) {
console.log(n);
if (n >= 1000) {
break;
}
}