<!-- 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; [groupByToIndex](./brick-next-pipes.groupbytoindex.md)

## groupByToIndex() function

返回一个数组的拷贝，并为每个元素新增一个分组索引字段。

 Others

**Signature:**

```typescript
export declare function groupByToIndex(value: Record<string, unknown>[], groupField: string, targetField: string): Record<string, unknown>[];
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  value | Record&lt;string, unknown&gt;\[\] | 对象数组。 |
|  groupField | string | 要分组的属性名。 |
|  targetField | string | 要新增的分组索引属性名。 |

**Returns:**

Record&lt;string, unknown&gt;\[\]

增加了分组索引属性的新数组。

## Remarks

新增的分组索引按分组属性升序排列。

## Example


```ts
const data = [
  { a: "3", b: "1" },
  { a: "1", b: "2" },
  { a: "1", b: "3" },
]
groupByIndex(data, "a", "groupIndex")
// Returns `[
//   { a: "3", b: "1", groupIndex: 1 },
//   { a: "1", b: "2", groupIndex: 0 },
//   { a: "1", b: "3", groupIndex: 0 },
// ]`
```


