<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@easyops-cn/brick-next-pipes](./brick-next-pipes.md) &gt; [mapToArray](./brick-next-pipes.maptoarray.md)

## mapToArray() function

将一个对象根据键值对映射转换为数组。

 Others

**Signature:**

```typescript
export declare function mapToArray(data: Record<string, unknown>, keyField: string, valueField: string): unknown[];
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  data | Record&lt;string, unknown&gt; | 对象。 |
|  keyField | string | 键名字段。 |
|  valueField | string | 键值字段。 |

**Returns:**

unknown\[\]

键值对映射后的数组。

## Remarks

该函数首先将输入的对象 `data` 拆分成键值对数组，再将每个键值对 `[key, value]` 转换为 `{ [keyField]: key, [valueField]: value }`<!-- -->， 最后返回这个新数组。

## Example


```ts
const data = { name: "Li Lei", age: 16, gender: "male" }
mapToArray(data, "label", "value")
// Returns `[
//   {label: "name", "value": "Li Lei"},
//   {label: "age", "value": 16},
//   {label: "gender", "value": "male"},
// ]`
```


