<!-- 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; [keyBy](./brick-next-pipes.keyby.md)

## keyBy() function

将指定属性（或迭代器执行结果）作为键名收集一个集合中的元素。

 Collection

**Signature:**

```typescript
export declare function keyBy(collection: unknown[] | Record<string, unknown>, iteratee: string | number): Record<string, unknown>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  collection | unknown\[\] \| Record&lt;string, unknown&gt; | 数据集合。 |
|  iteratee | string \| number | 属性名（或迭代器）。 |

**Returns:**

Record&lt;string, unknown&gt;

收集结果。

## Remarks

透传调用 [\_.keyBy](https://lodash.com/docs/#keyBy)<!-- -->。

## Example


```ts
const array = [
  { 'dir': 'left', 'code': 97 },
  { 'dir': 'right', 'code': 100 }
];

keyBy(array, function(o) {
  return String.fromCharCode(o.code);
});
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }

keyBy(array, 'dir');
// => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
```


