Please enable JavaScript.
Coggle requires JavaScript to display documents.
Map and Set - Coggle Diagram
Map and Set
Map
define
a collection of keyed data items, just like an Object
-
Methods and properties
-
map.set(key, value) – stores the value by the key.
map.get(key) – returns the value by the key, undefined if key doesn’t exist in map.
map.has(key) – returns true if the key exists, false otherwise.
-
-
-
note
-
-
-
Chaining
Every map.set call returns the map itself, so we can “chain” the calls
Map has a built-in forEach method, similar to Array
The insertion order is used, Map preserves this order
When a Map is created, we can pass an array (or another iterable) with key/value pairs for initialization
Iteration over Map
3 methods
map.keys() – returns an iterable for keys,
map.values() – returns an iterable for values,
map.entries() – returns an iterable for entries [key, value], it’s used by default in for..of.
-
-
Set
-
main method
new Set([iterable]) – creates the set, and if an iterable object is provided (usually an array), copies values from it into the set.
set.add(value) – adds a value, returns the set itself.
set.delete(value) – removes the value, returns true if value existed at the moment of the call, otherwise false.
set.has(value) – returns true if the value exists in the set, otherwise false.
-
-
-
-
-