flattenDepth
Modified on Mon, 07 Aug 2023
Description
Recursively flatten array up to depth times.
Syntax
flattenDepth(array, depth)
Parameters
Input Parameter | Type | Description |
---|---|---|
array | Array | The array to flatten. |
depth | number | The maximum recursion depth. |
Return value
Type |
---|
Array |
Sample
Example | Result | Description |
---|---|---|
flattenDepth([1, [2, [3, [4]]]], 1) | [1, 2, [3, [4]]] | Returns the new flattened array for depth 1 |
flattenDepth([1, [2, [3, [4]]]], 2) | [1, 2, 3, [4]] | Returns the new flattened array for depth 2 |
flattenDepth([1, [2, [3, [4]]]], 3) | [1, 2, 3, 4] | Returns the new flattened array for depth 3 |
To view all the List functions, click here.
See Also
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article