-
Notifications
You must be signed in to change notification settings - Fork 0
/
24_iterations.js
121 lines (84 loc) · 1.95 KB
/
24_iterations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// forof loop
const arr = [1, 2, 3, 4, 5]
for (const num of arr) {
console.log(num);
}
const greetings = "Hello world!"
for (const greet of greetings) {
console.log(`Each char is ${greet}`);
}
// Maps
const map = new Map()
map.set('IN', "India")
map.set('USA', "United States of America")
map.set('Fr', "France")
map.set('IN', "India")
console.log(map);
for (const key of map) {
console.log(key);
}
for (const [key, value] of map) {
console.log(key, ':-', value);
}
const myObject = {
'game1': 'NFS', // game1
'game2': 'Spiderman' // game2
}
/*
for (const [key, value] of myObject) {
console.log(key, ':-', value);
}
TypeError: myObject is not iterable
*/
const myObjectTwo = {
js: 'javascript',
cpp: 'c++',
rb: "ruby",
swift: "swift by apple"
}
for (const key in myObjectTwo) {
console.log(`${key} shortcut is for ${myObjectTwo[key]}`);
}
const programming = ["js", "rb", "py", "java", "cpp"]
for (const key in programming) {
console.log(programming[key]);
}
const mapone = new Map()
map.set('IN', "India")
map.set('USA', "United States of America")
map.set('Fr', "France")
map.set('IN', "India")
for (const key in mapone) {
console.log(key);
}
const coding = ["js", "ruby", "java", "python", "cpp"]
coding.forEach(function (item) {
console.log(item);
})
coding.forEach((val) => {
console.log(val);
})
function printMe(item) {
console.log(item);
}
coding.forEach(printMe)
coding.forEach((item, index, arr) => {
console.log(item, index, arr);
})
const myCoding = [
{
languageName: "javascript",
languageFileName: "js"
},
{
languageName: "java",
languageFileName: "java"
},
{
languageName: "python",
languageFileName: "py"
},
]
myCoding.forEach( (item) => {
console.log(item.languageName);
} )