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.