Array.flat_map
Array.flat_map
Function
First map and then expand the mapping result by depth 1.
Syntax
array.flat_map(callback)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| callback | Fn | No | Empty | The callback signature is fn(value, index, current). |
Return value
| Type | Description |
|---|---|
| Array | Returns the new array after mapping and expansion. |
Example
items = [1, 2] result = items.flat_map(fn(value) { [value, value * 10] }) // Output: [1,10,2,20] print result
Notes
- Expand only one level of array.