for of js code example
Example 1: javascript loop object
let obj = {
key1: "value1",
key2: "value2",
key3: "value3"
}
Object.keys(obj).forEach(key => {
console.log(key, obj[key]);
});
for (let key in obj) {
let value = obj[key];
console.log(key, value);
}
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: js for of
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
Example 6: for of loop javascript
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}