Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use a recursive helper function that iterates over each item. If the item is an array and the remaining depth is greater than 0, recurse with depth - 1. Otherwise, push the item to the result. Concatenate sub-results to build the flattened output.
The depth parameter controls how many levels of nesting to unwrap. Each recursive call decrements depth by 1, so arrays nested deeper than the specified depth are left as-is. Using Infinity flattens all levels.
Updated Feb 2026