DEV Community

Array Flattening in 5 lines

Dhilip kumar on October 25, 2019

Hello there ๐Ÿ‘‹, Array flattening is a process of reducing a Multi Dimensional Array into a single dimensional Array or with the dimensions specifie...
Collapse
 
georgecoldham profile image
George

You may also like Array.flat()

Supported on all browsers except edge and ie. if you are already using Babel then you can use without issue.

Collapse
 
kaos profile image
Kai Oswald

HOW TO FLATTEN AN ARRAY WITH JUST 1 LINE OF CODE! DEVS HATE HIM

Collapse
 
dhilipkmr profile image
Dhilip kumar

Post here is to understand how we could write utility functions ourselves. Getting to know what's happening under the Hood.๐Ÿ˜…

Collapse
 
georgecoldham profile image
George

Oh absolutely! Itโ€™s a valuable thing being able to understand whatโ€™s going on behind the scenes.

I only suggested .flat() incase you or others werenโ€™t aware of it. As Its a relatively new addition.

Thread Thread
 
dhilipkmr profile image
Dhilip kumar

Sure thing Agreed. I'll add about Array.flat too in the above Post . ๐Ÿ˜„

Collapse
 
pclement_ profile image
Peter Clement

Nice post! Thanks!

I've found this is a super common interview question, not so much in person / white boarding, but definitely online screens.

Collapse
 
dheerajmalik1 profile image
Dheeraj Malik

That gif :D