Prism · Arrays

$sortBy

Sorts an array by a key computed for each element. dir is asc unless it says desc; keys may be numbers or strings.

The source
{
  items: [
    { name: 'Carrot', price: 2 },
    { name: 'Apple', price: 1.5 },
    { name: 'Date', price: 3 },
  ],
}
The config
{
  $sortBy: {
    over: { $ref: '$.items' },
    as: 'item',
    by: { $get: { from: { $var: 'item' }, path: ['price'] } },
    dir: 'desc',
  },
}
What comes out
[
  { name: 'Date', price: 3 },
  { name: 'Carrot', price: 2 },
  { name: 'Apple', price: 1.5 },
]
Output matches the expected value

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