Avatar ·

How to merge/flatten an array of arrays in JavaScript?

Hello everyone! I'm a beginner in JavaScript and encountered a problem when working with nested arrays.\n\nI have an array that contains several other arrays inside:\n\n```javascript\nconst nestedArrays = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n];\n```\n\nI need to turn it into one flat array to get:\n\n```javascript\n[1, 2, 3, 4, 5, 6, 7, 8, 9]\n```\n\nI tried using the `concat()` method, but it doesn't work as I expected:\n\n```javascript\nconst result = nestedArrays.concat();\n// Result: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] — nothing changed\n```\n\nI tried writing a loop but got confused. Also, I have a more complex case: the array can contain not only numbers but also other arrays inside (deep nesting), for example:\n\n```javascript\nc