Maps & Sets Flashcards

1
Q

How do we create a new map?

A

let mapVar= new Map();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we check if a Map has a key of x?

A

mapVar.has(x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we set a key par for map?

A

mapVar.set(key1,value1);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do we get the value in any given map?

A

mapVar.get(key1);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we get the length of a map?

A

mapVar.size;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we get all the keys in a map?

A

mapVar.entries();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do we get all the values in a map?

A

mapVar.values();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we create a set?

A

let test = new Set(…arr);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a set used for?

A

A set is used to for example take an array an remove all duplicates from it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a weakmap?

A

A weak map is a Map however with 2 major changes, it is not enumerable so we cannot get the size of it or iterate over it using forEach(), and also it holds references to objects so if they were to be set to null in a map there would still be a reference but if it were referenced in a map we would receive an error when trying to recall that value.

All references that are gone end up being garbage collected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly