The groupBy method is a new addition to the JavaScript standard library that simplifies the process of grouping elements in an array based on a spe...
For further actions, you may consider blocking this person and/or reporting abuse
It is not rocket science to write some code to sort things in a similar way, but I can think of many other ways that "could" be useful. Here is a quick implementation that could probably made even shorter:
Though it is nice to have some convenience tools, we should consider if it is really worth to put anything in the JS core. Are there really so many cases people will use this? Javascript is already bloated with too many tools and concepts people need and struggle to learn.
I would prefer a language with a small but essential toolset that provides what´s necessary, not anything that´s possible. Things like this could better fit in some utility library
Unfortunately this is not correct at all, and will not work on ANY browser (I don't think). The proposal is for
Object.groupBy(and alsoMap.groupBy):Object.groupByreturns an object (with a null prototype), whereasMap.groupByreturns (you guessed it!) a map.I believe
Array.groupBywas dumped in favour of these because there was/is a popular existing library that implemented agroupBymethod on the Array prototype, so making it native could have caused havoc.You can read more here.
The groupBy method is relatively new and not yet supported by all browsers.
Checkout this: developer.mozilla.org/en-US/docs/W...
Yes, this link shows exactly what I was talking about:
Object.groupBy. It isn't a new array methodI am so happy we’re finally seeing support for this! 🎉
I made a small benchmark on this, might take a look:
dev.to/svidlak/is-javascript-objec...
Great