-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
37 lines (22 loc) · 669 Bytes
/
map.js
File metadata and controls
37 lines (22 loc) · 669 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
// Dsa Map in js
// A map is an unorderd collection of key-value pairs. both keys and values can be of any data type
// to retrive a value, you can use the th ecorresponding key
// Maps are iterables. They can be used with a for of loop
// implement
// map Data Structure
const map = new Map([['a', 1], ['b', 2],['c', 10]])
for(const [key,value] of map){
console.log(`${key}: ${value}`)
}
// set new key and value in map Dsa
map.set('c', 3)
// check a key has in map dsa
console.log(map.has('a'))
// delate key value in map
map.delete('b')
console.log(map)
// get size of map
console.log(map.size)
// clear all data in map
map.clear()
console.log(map)