Recurcive method
Code\n\n/**\n * @param {Array} arr\n * @param {number} depth\n * @return {Array}\n */\nvar flat = function (arr, n) {\n    if(n==0) return arr;\n    var ans = [
# Code\n```\n/**\n * @param {Array} arr\n * @param {number} depth\n * @return {Array}\n */\nvar flat = function (arr, n) {\n    if(n==0) return arr;\n    var ans = [];\n    for(var i=0; i<arr.length; i++){\n        if(Array.isArray(arr[i])){\n            ans.push(...flat(arr[i], n-1));\n        } else {\n            ans.push(arr[i]);\n        }\n    }\n    return ans;\n};\n\n```
['JavaScript']