๐—š๐—ฟ๐—ผ๐˜‚๐—ฝ๐—•๐˜† ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜: ๐—ง๐—ต๐—ฒ ๐—˜๐—ฎ๐˜€๐˜† ๐—ช๐—ฎ๐˜† ๐˜๐—ผ ๐—ข๐—ฟ๐—ด๐—ฎ๐—ป๐—ถ๐˜‡๐—ฒ ๐——๐—ฎ๐˜๐—ฎ

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.

Use Map.groupBy when your key is not a string. This works for:

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