1let list = [4, 5, 6];
2
3for (let i in list) {
4 console.log(i); // "0", "1", "2",
5}
6
7for (let i of list) {
8 console.log(i); // "4", "5", "6"
9}
1let panier = ['fraise', 'banane', 'poire'];
2
3for (const fruit of panier) {
4 // console.log(fruit);
5 console.log(panier.indexOf(fruit));
6}
1Object.prototype.objCustom = function () {};
2Array.prototype.arrCustom = function () {};
3
4let iterable = [3, 5, 7];
5iterable.foo = "hello";
6
7for (let i in iterable) {
8 console.log(i); // logs 0, 1, 2, "foo", "arrCustom", "objCustom"
9}
10
11for (let i of iterable) {
12 console.log(i); // logs 3, 5, 7
13}
14
1let arr = ['el1', 'el2', 'el3'];
2
3arr.addedProp = 'arrProp';
4
5// elKey are the property keys
6for (let elKey in arr) {
7 console.log(elKey);
8}
9
10// elValue are the property values
11for (let elValue of arr) {
12 console.log(elValue)
13}
1const iterable = [10, 20, 30];
2
3for (const value of iterable) {
4 console.log("fef"+value);
5}
6// 10
7// 20
8// 30
9
1let iterable = new Map([["a", 1], ["b", 2], ["c", 3]]);
2
3for (let entry of iterable) {
4 console.log(entry);
5}
6// [a, 1]
7// [b, 2]
8// [c, 3]
9
10for (let [key, value] of iterable) {
11 console.log(value);
12}
13// 1
14// 2
15// 3
16