Skip to content

Instantly share code, notes, and snippets.

@ptcc
Created March 15, 2017 18:14
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 ptcc/3bf56f4d40ccd0e4a7cc36eb96442130 to your computer and use it in GitHub Desktop.
Save ptcc/3bf56f4d40ccd0e4a7cc36eb96442130 to your computer and use it in GitHub Desktop.
flatten an array in ecmascript
const flattenArray = (nestedArray) =>
(nestedArray || []).reduce(
(acc, element) =>
Array.isArray(element)
? [...acc, ...flattenArray(element)]
: [...acc, element]
,[])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment