1let obj = {
2 key1: "value1",
3 key2: "value2",
4 key3: "value3"
5}
6
7Object.keys(obj).forEach(key => {
8 console.log(key, obj[key]);
9});
10// key1 value1
11// key2 value2
12// key3 value3
13
14// using for in - same output as above
15for (let key in obj) {
16 let value = obj[key];
17 console.log(key, value);
18}
1//for ... of statement
2
3const array1 = ['a', 'b', 'c'];
4
5for (const element of array1) {
6 console.log(element);
7}
8
9// expected output: "a"
10// expected output: "b"
11// expected output: "c"
12
1let panier = ['fraise', 'banane', 'poire'];
2
3for (const fruit of panier) {
4 // console.log(fruit);
5 console.log(panier.indexOf(fruit));
6}
1const array = ['hello', 'world', 'of', 'Corona'];
2
3for (const item of array) {
4 console.log(item);
5}
1for (let step = 0; step < 5; step++) {
2 // Runs 5 times, with values of step 0 through 4.
3 console.log('Walking east one step');
4}
5