Skip to content

Instantly share code, notes, and snippets.

@Astrochimp
Created November 1, 2018 03:31
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 Astrochimp/3c7b3f8992bd84668e5e2227e6286f21 to your computer and use it in GitHub Desktop.
Save Astrochimp/3c7b3f8992bd84668e5e2227e6286f21 to your computer and use it in GitHub Desktop.
function flattenArray(arr) {
const flattened = [].concat(...arr);
return flattened.some(item => Array.isArray(item)) ?
flattenArray(flattened) : flattened;
}
@Astrochimp
Copy link
Author

One way to flatten a multi dimensional array.

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