Member-only story
ES2019. Flatten arrays in Javascript with Array.flat()
“Flatten arrays” thanks to the new proposal ES2019
Today I bring you an article — recipe about Javascript that will help me to start talking about the news that ES2019 will bring and in which I will focus on how we can “flatten” arrays through Javascript.
So without entertaining much more, let’s see it!
But what is that about flattening?
Flattening arrays is a very useful operation that performs the following:
That is, by passing an array of arrays, what it does is transform it into an array of a single dimension.
However, this operation is not implemented natively in Javascript, so it has been necessary to use some imagination (or Stackoverflow 😋) to obtain any possible implementation.
Some flatArray() implementations
With a simple Google search you will find many flatArray implementations. For example we have the following:
const merged = [].concat.apply([], arrays);






