Skip to content

Instantly share code, notes, and snippets.

@Zensavona
Created December 20, 2018 03:28
Show Gist options
  • Save Zensavona/0cb1de87df4706e2f280eaba06db5a03 to your computer and use it in GitHub Desktop.
Save Zensavona/0cb1de87df4706e2f280eaba06db5a03 to your computer and use it in GitHub Desktop.
Flatten Array JS
const flatten = list => list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
)
const array = [[1,2,[3]],4]
flatten(array) // [ 1, 2, 3, 4 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment