The lodash _.flatten method for flatting down a multi dimensional array
So some of the methods in lodash can come in handy, and really do help to save time with certain projects where I might make lodash part of the stack. Todays post on lodash is one of those lodash methods that I might actually use now and then which is the _.flatten method. However when it comes to just working with native javaScript these days there is also the flat array prototype in native javaScript.
The _.flatten, and also _.flattenDeep methods are one of many methods that help with the task of working with arrays of arrays, which are a kind of multidimensional array in javaScript. Flatten can be used to flatten down an array of arrays into a single array, thus making it a method that can be thought of as a reversal of _.chunk. With that said the lodash chunk method will do the inversion of flatten which is to break an array of elements down into an array of arrays of elements.
So then taking a moment to play around with flatten and chunk methods in lodash is one way to go about seeing why these two methods can often come in handy. So lets look at a few examples when it comes to working with arrays of arrays, and the lodash flatten method in javaScript.