Map Methods
Method Description
new Creates a new Map object
Map() const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
set() Sets the value for a key in a
Map
[Link]("apples", 500);
get() Gets the value for a key in a
Map
[Link]("apples");
clear() Removes all the elements
from a Map
delete() Removes a Map element
specified by a key
[Link]("apples");
has() Returns true if a key exists
in a Map
forEach( Invokes a callback for each
) key/value pair in a Map
entries() Returns an iterator object
with the [key, value] pairs in
a Map
keys() Returns an iterator object
with the keys in a Map
values() Returns an iterator object of
the values in a Map
vaScript Objects vs Maps
Differences between JavaScript
Objects and Maps:
Object Map
Iterable Not directly iterable Directly iterable
Size Do not have a size Have a size property
property
Key Types Keys must be Strings Keys can be any
(or Symbols) datatype
Key Order Keys are not well Keys are ordered by
ordered insertion
Defaults Have default keys Do not have default
keys