-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
48 lines (37 loc) · 997 Bytes
/
Copy pathmap.js
File metadata and controls
48 lines (37 loc) · 997 Bytes
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
// map holds key values
const map=new Map()
map.set('BAN',"Bangladesh")
map.set('UN',"United Nation")
map.set('USA',"United states of America")
map.set('UK',"United Kingdom")
console.log(map);
// for...in is for objects: The for...in loop is designed to iterate over the enumerable properties of plain objects, not Map objects.
for(const key of map)
{
console.log(key);
}
for(const [key,value] of map)
{
console.log(key);
}
const person = {
name: 'John',
age: 30,
occupation: 'Developer'
};
for (let key in person) {
console.log(`${key}: ${person[key]}`);
}
const fruits = ['apple', 'banana', 'cherry'];
for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}
fruits.forEach(function (item){console.log(`${item}`);
})
// arrow function
fruits.forEach((item)=>{console.log(`${item}`);
})
function print(item){console.log(`${item}`)}
fruits.forEach(print)
fruits.forEach((item,index,arr)=>{console.log(`${item},${index},${arr}`);
})