for ... of.. recursive
Code
# Code
```typescript []
type MultiDimensionalArray = (number | MultiDimensionalArray)[];

var flat = function (arr:  MultiDimensionalArray, n: number):  MultiDimensionalArray {
    const res = [];
    const flatUtil = (arr: MultiDimensionalArray, n: number) => {
        for (const val of arr) {
            if (Array.isArray(val) && n > 0) {
                flatUtil(val, n -1)
            } else {
                res.push(val);
            }
        }
    }

    flatUtil(arr, n);
    return res;
};
```
['TypeScript']