The basic array class has .map
, .forEach
, .filter
, and .reduce
, but .groupBy
i noticably absent, preventing me f
you could add the function to the array prototype in your app (note some don't recomend this: Why is extending native objects a bad practice?):
Array.prototype.groupBy = function(/* params here */) {
let array = this;
let result;
/* do more stuff here*/
return result;
};
Then create an interface in typescript like this:
.d.ts version:
interface Array
{
groupBy(func:(x:T) => string): Group[]
}
OR in a normal ts file:
declare global {
interface Array
{
groupBy(func:(x:T) => string): Group[]
}
}
Then you can use:
props.tags.groupBy((t)=>t.category_name)
.map((group)=>{
[...]
})