JavaScript Easy Solution
\n\n# Code\n\n/**\n * @param {any[]} arr\n * @param {number} depth\n * @return {any[]}\n */\nvar flat = function (arr, n) {\n    let res = [];\n    const flatte
\n\n# Code\n```\n/**\n * @param {any[]} arr\n * @param {number} depth\n * @return {any[]}\n */\nvar flat = function (arr, n) {\n    let res = [];\n    const flattening = (nums, l) => {\n      for (const num of nums) {\n        if (Array.isArray(num) && l > 0 && l <= n) {\n          flattening(num, l - 1);\n        } else {\n          res.push(num);\n        }\n      }\n    }\n\n    flattening(arr, n);\n    return res;\n};\n```\n![UpvoteLeetcode.jpeg](https://assets.leetcode.com/users/images/73113fa9-839a-4d44-945e-4194fe941d2e_1685091792.7403052.jpeg)\n
['JavaScript']