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.


export declare function buildLookupMap<Key, InType extends object, OutType = InType>(list: InType[], keyName: StringKeyOf<InType>, reducer: (accumulator: OutType | undefined, current: InType) => OutType): Map<Key, OutType>;


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


Map<Key, OutType>