๐๐ฟ๐ผ๐๐ฝ๐๐ ๐ถ๐ป ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐: ๐ง๐ต๐ฒ ๐๐ฎ๐๐ ๐ช๐ฎ๐ ๐๐ผ ๐ข๐ฟ๐ด๐ฎ๐ป๐ถ๐๐ฒ ๐๐ฎ๐๐ฎ
Stop using reduce to organize arrays. It makes code hard to read.
ECMAScript 2024 gives you a simpler way. Use Object.groupBy and Map.groupBy.
Grouping data turns a list into an index. You use a key to organize items. This makes searches faster.
Use Object.groupBy when your key is a string.
- Pass the list.
- Pass a function for the key.
- Get an organized object.
Use Map.groupBy when your key is not a string. This works for:
- Dates
- Objects
- Symbols
Map.groupBy keeps the original type of the key. This prevents errors.
These tools make your code leaner. Most modern browsers support them. You only lose support for Internet Explorer.
Source: https://dev.to/sucodelarangela/groupby-in-javascript-the-easy-way-to-index-and-organize-data-53op