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)