[**@bondsports/general**](../README.md) • **Docs**

***

[@bondsports/general](../globals.md) / arrayToMap

# Function: arrayToMap()

> **arrayToMap**\<`T`\>(`array`): `Map`\<`number`, `T`\>

Converts an array of objects into a Map, where the keys are the `id` properties of the objects.

## Type Parameters

• **T** *extends* `object`

The type of the objects in the array, which must extend an object containing a numeric `id` property.

## Parameters

• **array**: `T`[]

The array of objects to convert. Can be null or undefined, in which case an empty Map is returned.

## Returns

`Map`\<`number`, `T`\>

A Map where the keys are the `id` values from the objects and the values are the objects themselves.

## Examples

```ts
const input = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
const result = arrayToMap(input);
// result is a Map with:
//   1 => { id: 1, name: 'Alice' }
//   2 => { id: 2, name: 'Bob' }
```

```ts
const emptyResult = arrayToMap([]);
// emptyResult is an empty Map
```

```ts
const nullResult = arrayToMap(null);
// nullResult is an empty Map
```

## Defined in

[utils/array.util.ts:268](https://github.com/Bond-Sports/bondUtils/blob/545f16ceb055481acfd7641d7809c0f252d3a5e6/packages/general/src/utils/array.util.ts#L268)
