Array.flat
Array.flat
Function
Expand nested arrays depth-wise.
Syntax
array.flat(depth)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| depth | Int | No | 1 | Expansion depth; negative numbers are treated as 0. |
Return value
| Type | Description |
|---|---|
| Array | Returns the new expanded array. |
Example
items = [1, [2, [3]]] result = items.flat(2) // Output: [1,2,3] print result
Notes
- The original array will not be modified.