@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
54 lines (36 loc) • 2.04 kB
Markdown
---
lang: en
title: 'API docs: context.resolvemap'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.resolvemap.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [resolveMap](./context.resolvemap.md)
## resolveMap() function
Resolve entries of an object into a new object with the same keys. If one or more entries of the source object are resolved to a promise by the `resolver` function, this method returns a promise which will be resolved to the new object with fully resolved entries.
<b>Signature:</b>
```typescript
export declare function resolveMap<T, V>(map: MapObject<T>, resolver: (val: T, key: string, values: MapObject<T>) => ValueOrPromise<V>): ValueOrPromise<MapObject<V>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| map | [MapObject](./context.mapobject.md)<!-- --><T> | The original object containing the source entries |
| resolver | (val: T, key: string, values: [MapObject](./context.mapobject.md)<!-- --><T>) => [ValueOrPromise](./context.valueorpromise.md)<!-- --><V> | A function resolves an entry to a value or promise. It will be invoked with the property value, the property name, and the source object. |
<b>Returns:</b>
[ValueOrPromise](./context.valueorpromise.md)<!-- --><[MapObject](./context.mapobject.md)<!-- --><V>>
## Example
- Example 1: resolve all entries synchronously
```ts
const result = resolveMap({a: 'x', b: 'y'}, v => v.toUpperCase());
```
The `result` will be `{a: 'X', b: 'Y'}`<!-- -->.
- Example 2: resolve one or more entries asynchronously
```ts
const result = resolveMap({a: 'x', b: 'y'}, v =>
Promise.resolve(v.toUpperCase()),
);
```
The `result` will be a promise of `{a: 'X', b: 'Y'}`<!-- -->.