for of example
Example 1: javascript for...of index
for (const [i, v] of ['a', 'b', 'c'].entries()) {
console.log(i, v)
}
Example 2: for of and for in javascript
let arr = ['el1', 'el2', 'el3'];
arr.addedProp = 'arrProp';
for (let elKey in arr) {
console.log(elKey);
}
for (let elValue of arr) {
console.log(elValue)
}
Example 3: 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;
}
}
Example 4: use these instead of a for loop javascript
const array = [1,2,3,4,5];const evenNumbers = array.filter(function(elem) {