Skip to content

Instantly share code, notes, and snippets.

@imjakechapman
Created March 27, 2020 22:43
Show Gist options
  • Save imjakechapman/5b628ef767a241a324f7d64c9f0e2a6c to your computer and use it in GitHub Desktop.
Save imjakechapman/5b628ef767a241a324f7d64c9f0e2a6c to your computer and use it in GitHub Desktop.
Flatten a nested array
const flatten = (arr) => {
return Array.isArray(arr) ? [].concat(...arr.map(flatten)) : arr;
}
let ar = [[1,2,3], [4, [5, 6]], [[7, [8, [9]]]]]; // [1, 2, 3, 4, 5, 6, 7, 8, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment