More you should know about Flatten || Best Soln
\n\uD83D\uDCA1 It is a process through which we can reduce the dimension of the array\n\n \n\n- We can use concat() method for flattening the array\n\njsx\nlet 
<aside>\n\uD83D\uDCA1 It is a process through which we can reduce the dimension of the array\n\n</aside>\n\n- We can use concat() method for flattening the array\n\n```jsx\nlet arr = [[1,2],[3,[4,9]],[5,6]];\n\nlet flattened= [].concat(...arr);\nconsole.log(flattened); //[ 1, 2, 3, [ 4, 9 ], 5, 6 ]\n```\n\n- Use array.flat() method, here you have to give the depth level of the array\n    \n    for example: array.flat(2)\n    \n    ```jsx\n    let arr = [[1,2],[3,[4,9]],[5,6]];\n    \n    console.log(arr.flat(2)); //[ 1, 2, 3,  4, 9 , 5, 6 ]\n    ```\n    \n- We can also make our own custom flat function for an array with the help of recursion\n\n```jsx\nlet arr = [[1,2],[3,[4,9]],[5,6]];\n\nfunction customFlat(arr, dept = 1){\n    let result = [];\n    arr.forEach((ar) => {\n        if(Array.isArray(ar) && dept>0){\n            result.push(...customFlat(ar, dept-1))\n        } else result.push(ar)\n    });\n    return result;\n}\n\nconsole.log(customFlat(arr, 2));\n```\n\n\n\n# Code (The Simple Approach)\n```javascript []\n/**\n * @param {Array} arr\n * @param {number} depth\n * @return {Array}\n */\nvar flat = function (arr, n) {\n    let result = [];\n    arr.forEach((ar) => {\n        if(Array.isArray(ar) && n>0){\n            result.push(...flat(ar,n-1));\n        }\n        else{\n            result.push(ar);\n        }\n    })\n\n    return result;\n};\n```
['JavaScript']