Skip to content

Commit 3ff6fe5

Browse files
committed
basic map in js 🗽🚀
1 parent fd5f8a6 commit 3ff6fe5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

01 - JavaScript-Basics/map.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let sayings = new Map();
2+
sayings.set('dog', 'woof');
3+
sayings.set('cat', 'meow');
4+
sayings.set('elephant', 'toot');
5+
sayings.size; // 3
6+
sayings.get('fox'); // undefined
7+
sayings.has('bird'); // false
8+
sayings.delete('dog');
9+
sayings.has('dog'); // false
10+
11+
for (let [key, value] of sayings) {
12+
console.log(key + ' goes ' + value);
13+
}
14+
// "cat goes meow"
15+
// "elephant goes toot"
16+
17+
sayings.clear();
18+
sayings.size; // 0
19+
20+
let numbers = [4, 9, 20, 25, 29, 44, 88, 99];
21+
let num = numbers.map(Math.sqrt);
22+
23+
console.log(num);
24+
25+
let nums = [4, 9, 20, 25, 29, 44, 88, 99];
26+
let newarray = numbers.map(myFunction);
27+
28+
function myFunction(num) {
29+
return num * 10;
30+
}
31+
32+
console.log(newarray);

0 commit comments

Comments
 (0)