Skip to content

Instantly share code, notes, and snippets.

@jasperblues
Created December 11, 2018 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperblues/383283c0f295439bf4234e1f00bbeaba to your computer and use it in GitHub Desktop.
Save jasperblues/383283c0f295439bf4234e1f00bbeaba to your computer and use it in GitHub Desktop.
const flatten = arr => arr.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
flatten([[1, 2, [3]], 4]);
@jasperblues
Copy link
Author

If the array arrays are not nested we can just use the spread operator:

const result = [].concat(...[[1,2], [3,4]])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment