Best JavaScript Solution for Beginner 💛
Code\n\n/**\n * @param {any[]} arr\n * @param {number} depth\n * @return {any[]}\n */\nvar flat = function (arr, n) {\n    if (n === 0) {\n        return arr;\n
# Code\n```\n/**\n * @param {any[]} arr\n * @param {number} depth\n * @return {any[]}\n */\nvar flat = function (arr, n) {\n    if (n === 0) {\n        return arr;\n    }\n    \n    let answer = [];\n    \n    arr.forEach(element => {\n        if (n > 0 && Array.isArray(element)) {\n            answer.push(...flat(element, n - 1));\n        } else {\n            answer.push(element);\n        }\n    });\n    \n    return answer;\n};\n\n```
['JavaScript']