xxxxxxxxxx
const array = ['hello', 'world', 'of', 'Corona'];
for (const item of array) {
console.log(item);
}
xxxxxxxxxx
let list = [4, 5, 6];
for (let i in list) {
console.log(i); // "0", "1", "2",
}
for (let i of list) {
console.log(i); // "4", "5", "6"
}
xxxxxxxxxx
//for ... of statement
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
// expected output: "a"
// expected output: "b"
// expected output: "c"
xxxxxxxxxx
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
// expected output: "a"
// expected output: "b"
// expected output: "c"
xxxxxxxxxx
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
// expected output: "a"
// expected output: "b"
// expected output: "c"
xxxxxxxxxx
let panier = ['fraise', 'banane', 'poire'];
for (const fruit of panier) {
// console.log(fruit);
console.log(panier.indexOf(fruit));
}
xxxxxxxxxx
let fruits = ["apple", "pear", "plum", "orange", "cherry"];
for(let fruit of fruits)
{
console.log(fruit);
}
xxxxxxxxxx
const people = [{ name: 'Karl', location: 'UK' },
{ name: 'Steve', location: 'US' }];
for (const person of people) {
console.log(person.name); // "karl", then "steve"
console.log(person.location); // "UK", then "US"
}
xxxxxxxxxx
let colors = ['Red', 'Green', 'Blue'];
for (const [index, color] of colors.entries()) {
console.log(`${color} is at index ${index}`);
}Code language: JavaScript (javascript)
xxxxxxxxxx
const iterable = [10, 20, 30];
for (const value of iterable) {
console.log(value);
}
// 10
// 20
// 30