Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Last active November 23, 2017 02:05
Show Gist options
  • Select an option

  • Save crobinson42/8e20846c6dd2843af23cd7c1b5014611 to your computer and use it in GitHub Desktop.

Select an option

Save crobinson42/8e20846c6dd2843af23cd7c1b5014611 to your computer and use it in GitHub Desktop.
Citrusbyte.com - flatten array
function flatten (a) {
return [].concat( ...a.map(x => Array.isArray(x) ? flatten(x) : x) )
}
flatten([1, 2, [3, 4, [5], 6, [7, [8]]]])
// [ 1, 2, 3, 4, 5, 6, 7, 8 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment