DEV Community

[Comment from a deleted post]
Collapse
 
pengeszikra profile image
Peter Vivo

Good solution, but maybe use .flat

[1,2,3,[4,5,[6,7]],8,[9,[10,11]]].flat() // [1,2,3,4,5,[6,7],8,9,[10,11]]
Enter fullscreen mode Exit fullscreen mode

flat parameter is recursion level:

[1,2,3,[4,5,[6,7]],8,[9,[10,11]]].flat(2) // [1,2,3,4,5,6,7,8,9,10,11]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ip127001 profile image
Rohit Kumawat

Thanks for reading the article and for this solution 🙌. Really appreciate it.
But yeah I covered this solution because it covers recursion as well.