Would you like to hear more about Set
and Map
objects in JavaScript?
Let's catch up with them on this thread π§΅
Set
in JavaScript π
π It's not key/value like the Object type. Keys are just values exposed
π Don't accept duplicated values
π It's iterable with forEarch
method and for...of
π Conceptually is similar to []
π‘ Set
is useful to remove duplicates on []
.
Map
in JavaScript π
π Allow/preserve any key type. Even objects
π Don't expose insecure data properties
π Iterate with forEarch
method and for...of
π Stay the insertion order doesn't matter the type
π‘ Prefer Map
instead of {}
for client-side data manipulation.
Thoughts on Map
, Set
, {}
, and []
in JavaScript π
π Each has a specific usage in JS
π Use {}
for data traffic from the server.
π Set
helps apply omit, diff, etc. on []
π Map
return size. {}
don't return size
π£ There's not a silver bullet. Use them carefully.
π Hope that you now understand better such useful objects on JavaScript, they are highly valuable, and master them will make you a better JavaScript Developer.
Top comments (0)