DEV Community

Discussion on: JavaScript Sets are Excellent!

 
jacobmgevans profile image
Jacob Evans

It is not the only intended use for Sets, they are also wicked fast and efficient at locating elements to see if they exist and deleting elements. Both are built-in functionality for Sets. I like to think of sets as almost a Hybrid of Maps and Arrays, its a bit of an oversimplification and generalization but I personally like thinking about them in that way.

One major difference is Arrays are Indexed collections while Sets are Keyed collections, which allows for some of the behaviors I mentioned that are similar to Maps like .has and .delete() and also related to why duplicates are not allowed (Maps also can't have duplicates)

Thread Thread
 
seanmclem profile image
Seanmclem

I didn't know that map was its own type of object - in addition to a function on an array
developer.mozilla.org/en-US/docs/W...