function toRecord<T, K, V>(array, selector, fn): Record<T[K], V>;Defined in: aa-sdk/core/src/utils/index.ts:177
Converts an array of objects into a record (object) where each key is determined by the specified selector and the value is determined by the provided function.
import { toRecord } from "@aa-sdk/core";
import { sepolia, mainnet } from "viem/chains";
const addressesByChain = toRecord([sepolia, mainnet], "id", () => "0x..."); // { [sepolia.id]: "0x...", [mainnet.id]: "0x..." }| Type Parameter |
|---|
|
|
|
| Parameter | Type | Description |
|---|---|---|
|
| The array of objects to convert to a record |
|
| The key used to select the property that will become the record's key |
| ( | The function that transforms each item in the array into the record's value |
Record<T[K], V>
The resulting record object