Recursion
Code
# Code
```javascript []
var flat = function (arr, n) {
    const res = [];
    for (let i = 0; i < arr.length; i++) {
        if (Array.isArray(arr[i]) && n) {
            res.push(...flat(arr[i], n - 1));
        } else {
            res.push(arr[i]);
        }
    }
    return res;
};
```
['JavaScript']