Skip to content

Instantly share code, notes, and snippets.

@josenaves
Created November 29, 2017 16:59
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 josenaves/0763b12e126d0d12d4eae5f305e48758 to your computer and use it in GitHub Desktop.
Save josenaves/0763b12e126d0d12d4eae5f305e48758 to your computer and use it in GitHub Desktop.
Flatten an array (ES6)
const arr = [[1,2,[3]],4];
const flattenArray = list =>
list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flattenArray(b) : b), []
);
console.log(flattenArray(arr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment