0% found this document useful (0 votes)
23 views4 pages

Map Methods Object

The document outlines various methods for working with JavaScript Map objects, including creating, setting, getting, clearing, deleting, and checking for keys. It also compares JavaScript Objects and Maps, highlighting differences in iterability, size properties, key types, key order, and default keys. Maps provide more flexibility and functionality compared to traditional Objects.

Uploaded by

taheyo1370
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Map Methods Object

The document outlines various methods for working with JavaScript Map objects, including creating, setting, getting, clearing, deleting, and checking for keys. It also compares JavaScript Objects and Maps, highlighting differences in iterability, size properties, key types, key order, and default keys. Maps provide more flexibility and functionality compared to traditional Objects.

Uploaded by

taheyo1370
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like