@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
37 lines (24 loc) • 1.31 kB
Markdown
---
lang: en
title: 'API docs: repository.buildlookupmap'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/repository
permalink: /doc/en/lb4/apidocs.repository.buildlookupmap.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/repository](./repository.md) > [buildLookupMap](./repository.buildlookupmap.md)
## buildLookupMap() function
Returns a map which maps key values(ids) to instances. The instances can be grouped by different strategies.
<b>Signature:</b>
```typescript
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](./repository.stringkeyof.md)<!-- --><InType> | key name of the source |
| reducer | (accumulator: OutType \| undefined, current: InType) => OutType | a strategy to reduce inputs to single item or array |
<b>Returns:</b>
Map<Key, OutType>