I've spent the last week trying to use #JavaScript Map and Set instead of...


I've spent the last week trying to use #JavaScript Map and Set instead of plain ol' arrays and objects.

My verdict? Not worth it.

The lack of basic methods like map, find, filter, reduce make them a hassle.

I'd only consider them in rare performance intensive applications.
To clarify, there are good reasons to use Map or Set.

Map supports non-string keys. Set enforces uniqueness. Etc.

Point is, if I don’t need their unique benefits, I prefer plain arrays and objects. The ergonomics are better.

Summary: They’re specialized power tools. 🧰
Also, the real mistake I realized this week: I was trying to use Map as a general replacement for array. 🤦‍♂️

It’s not a generalized tool. It’s a specialized tool with tradeoffs.

Benefits: Non-string key support, size prop, predictable order, etc

Cost: Ergonomics

View original on X