Skip to main content
Version: 2.x

API Reference > @easyops-cn/brick-next-pipes > groupBy

groupBy() function

把一个集合按指定属性(或迭代器执行结果)的值进行分组。

Collection

Signature:

export declare function groupBy(
collection: unknown[] | Record<string, unknown>,
iteratee: string | number
): Record<string, unknown[]>;

Parameters

ParameterTypeDescription
collectionunknown[] | Record<string, unknown>数据结合。
iterateestring | number属性名(或迭代器)。

Returns:

Record<string, unknown[]>

分组结果。

Remarks

透传调用 _.groupBy

Example

groupBy([6.1, 4.2, 6.3], Math.floor);
// => { '4': [4.2], '6': [6.1, 6.3] }

groupBy(["one", "two", "three"], "length");
// => { '3': ['one', 'two'], '5': ['three'] }