javscript for of code example
Example 1: 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 2: use these instead of a for loop javascript
const array = [1, 2, 3];array.forEach(function(elem, index, array) { array[index] = elem * 2;});console.log(array);
Example 3: 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 4: use these instead of a for loop javascript
const array = [1,2,3,4,5];const evenNumbers = array.filter(function(elem) {