toRecord

1function 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.

Example

1import { toRecord } from "@aa-sdk/core";
2import { sepolia, mainnet } from "viem/chains";
3
4const addressesByChain = toRecord([sepolia, mainnet], "id", () => "0x..."); // { [sepolia.id]: "0x...", [mainnet.id]: "0x..." }

Type Parameters

Type Parameter

T extends { [K in string | number | symbol]: string | number | symbol }

K extends string | number | symbol

V

Parameters

ParameterTypeDescription

array

T[]

The array of objects to convert to a record

selector

K

The key used to select the property that will become the record’s key

fn

(item) => V

The function that transforms each item in the array into the record’s value

Returns

Record<T[K], V>

The resulting record object