Skip to content

Instantly share code, notes, and snippets.

@the-creature
Created February 1, 2017 04:27
Show Gist options
  • Save the-creature/7ef4e3575c73c094219d05225590e0e8 to your computer and use it in GitHub Desktop.
Save the-creature/7ef4e3575c73c094219d05225590e0e8 to your computer and use it in GitHub Desktop.
es6 flat array
const flatten = arr => arr.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
testArr = [[1,2,[3]],4]
console.log(flatten(testArr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment