for of array code example
Example 1: js loop array
let colors = ['red', 'green', 'blue'];
for (const color of colors){
console.log(color);
}
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: javascript for of
const array = ['hello', 'world', 'of', 'Corona'];
for (const item of array) {
console.log(item);
}
Example 4: for of js
let panier = ['fraise', 'banane', 'poire'];
for (const fruit of panier) {
console.log(panier.indexOf(fruit));
}
Example 5: for array javascript
let iterable = [10, 20, 30];
for (let value of iterable) {
value += 1;
console.log(value);
}
Example 6: 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);