Prism · Structure
$keyBy
Turns a list of records into an object keyed by a value computed for each. Where two records give the same key, the later one stays.
{
products: [
{ sku: 'A1', name: 'Apple', price: 1.5 },
{ sku: 'B1', name: 'Banana', price: 0.5 },
{ sku: 'C1', name: 'Cherry', price: 3 },
],
}{
$keyBy: {
over: { $ref: '$.products' },
as: 'p',
key: { $get: { from: { $var: 'p' }, path: ['sku'] } },
},
}{
A1: { sku: 'A1', name: 'Apple', price: 1.5 },
B1: { sku: 'B1', name: 'Banana', price: 0.5 },
C1: { sku: 'C1', name: 'Cherry', price: 3 },
}Runs in this page on the installed package. The input and the expected output are defined by the example.