Reduce/group array coming from a collection?

Hey again WeWeb team, diving into workflows and custom JS now.

Should I be able to do something like this? I have a collection, in this case of tags. Each tag has an id, name, and category. I want to get the collection, then reduce the array to group the tags by category, so that the resulting returned object looks something like this:

groupedTags = {
   Business models = {
      [ id: 1, name: B2B, category: Business models ],
      [ id: 4, name: whatever, category: Business models]
   },
   Funding environments = {
    [ tags ]
   }
}

What I have in the screenshot doesn’t return anything. Do I need to make variables on this page instead of declaring them in the custom JS? Is there a better way to do this in WeWeb?

the custom js is wrapped i side a function. If you want to make a valie available for the next actions you need to return it.
Try adding return groupedTags at the end.

*facepalm thank you

if this is helpful to anyone else:


set the result to an object var groupedTags

Then display each group in a collection list:

and the heading is the key of the groupedTags object array[n]:

thanks @dorilama

1 Like