Prism · Structure

$groupBy

Sorts a list of records into an object of lists, one for each value of a computed key.

The source
{
  items: [
    { name: 'Apple', category: 'fruit' },
    { name: 'Banana', category: 'fruit' },
    { name: 'Carrot', category: 'vegetable' },
    { name: 'Date', category: 'fruit' },
    { name: 'Eggplant', category: 'vegetable' },
  ],
}
The config
{
  $groupBy: {
    over: { $ref: '$.items' },
    as: 'item',
    key: { $get: { from: { $var: 'item' }, path: ['category'] } },
  },
}
What comes out
{
  fruit: [
    { name: 'Apple', category: 'fruit' },
    { name: 'Banana', category: 'fruit' },
    { name: 'Date', category: 'fruit' },
  ],
  vegetable: [
    { name: 'Carrot', category: 'vegetable' },
    { name: 'Eggplant', category: 'vegetable' },
  ],
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.