Map Flashcards
Map is similar to what DS?
Object. Both operate w/ key value pairs.
Key types
Any value (array, Objs, or any primitive)
Key order
A Map iterates in the order of insertion
Is a Map iterable?
Yes. Can be directly iterated.
Which performs better, Object or Map?
Map when frequently adding & removing kv pairs.
How to return the number of elements?
Map.size
Map.clear()
Does- removes all elements from Map object
Params- none
Returns- undefined
Map.delete()
Does- removes a specified element
Params- key
Returns- bool. True if object existed and was removed. False if it doesn’t exist
Map.entries() vs Map.keys() vs Map.values()
Entries - returns a new Map iterator w/ key-value pairs in insertion order
Keys - returns a new Map iterator w/ all keys in insertion order
Values- returns a new Map iterator w/ all values in insertion order
Map.get()
Does- returns a specified element from Map object
Params -Key
Returns - associated elements value or undefined
Map.set()
Does - inserts/updates a key-value in Map object
Params - key, value
Returns Map object
Map.has()
Does - tells if key exists in Map object
Params - key
Returns - bool based on if key exists