Page Contents
Home > @loopback/repository > buildLookupMap
buildLookupMap() function
Returns a map which maps key values(ids) to instances. The instances can be grouped by different strategies.
Signature:
export declare function buildLookupMap<Key, InType, OutType = InType>(list: InType[], keyName: StringKeyOf<InType>, reducer: (accumulator: OutType | undefined, current: InType) => OutType): Map<Key, OutType>;
Parameters
Parameter | Type | Description |
---|---|---|
list | InType[] | an array of instances |
keyName | StringKeyOf<InType> | key name of the source |
reducer | (accumulator: OutType | undefined, current: InType) => OutType | a strategy to reduce inputs to single item or array |
Returns:
Map<Key, OutType>