Map and Set Flashcards
What is a map object?
An object with keyed data items but can take keys of any type. Strings Numbers Boolean Objects Null Undefined Infinity NaN
Create a new map
new Map()
Store a value by the key in a map object
Map.prototype.set(key, value)
Return the value by the key in a map object, undefined if key doesn’t exist in map.
Map.prototype.get(key)
Return true if the key exists in a map object, false otherwise.
Map.prototype.has(key)
Removes the value by the key in a map object
Map.prototype.delete(key)
Remove everything from the map object and return undefined
Map.prototype.clear()
Returns the current element count in a map object
Map.prototype.size
What does: new Map() do and/or return?
Create a new map
What does:
Map.prototype.set()
do and/or return?
Store a value by the key in a map object
Map.prototype.set(key, value)
Returns the map itself (can chain)
What does:
Map.prototype.get(key)
do and/or return?
Return the value by the key in a map object, undefined if key doesn’t exist in map.
What does:
Map.prototype.has(key)
do and/or return?
Return true if the key exists in a map object, false otherwise.
What does:
Map.prototype.delete(key)
do and/or return?
Removes the value by the key in a map object
Returns true or false based on whether the key existed or not.
What does:
Map.prototype.clear()
do and/or return?
Remove everything from the map object
Returns undefined
What does:
Map.prototype.size
do and/or return?
Returns the current element count in a map object
Does:
map[key]
map.key
work with map objects?
Yes, and they will behave like regular objects in this way
Returns iterables of keys, entries or values of a map objects
Map.prototype.keys()
Map.prototype.values()
Map.prototype.entries() (it’s used by default in for..of.
)
What order do map objects iterate over keys, values and entries?
The order they were added.