Function: map()
ts
function map<T, R>(collection, iteratee): T extends readonly unknown[] ? R[] : Record<string, R>;Maps over an array or object and returns a transformed collection of the same shape. 对数组或对象执行映射,并返回相同结构的转换结果。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<string, unknown> | readonly unknown[] | The source collection type / 源集合类型 |
R | The mapped value type / 映射值类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
collection | T | The source collection / 源集合 |
iteratee | (value, key, collection) => R | The mapping function / 映射函数 |
Returns
T extends readonly unknown[] ? R[] : Record<string, R>
The mapped collection / 映射后的集合
Example
ts
map({ a: 1, b: 2 }, (value) => value * 2)
// => { a: 2, b: 4 }Since
1.2.0