Function: reduce()
ts
function reduce<T, R>(
collection,
iteratee,
initialValue): R;Reduces an array or object into a single accumulated value. 将数组或对象归约为单个累计值。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<string, unknown> | readonly unknown[] | The source collection type / 源集合类型 |
R | The accumulator type / 累加器类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
collection | T | The source collection / 源集合 |
iteratee | (accumulator, value, key, collection) => R | The reducer function / 归约函数 |
initialValue | R | The initial accumulator / 初始累加值 |
Returns
R
The reduced result / 归约结果
Example
ts
reduce({ a: 1, b: 2 }, (acc, value) => acc + value, 0)
// => 3Since
1.2.0