Skip to content

Instantly share code, notes, and snippets.

@wojciak
Last active October 24, 2018 04:47
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 wojciak/18b661007b885912f60d8663561d4fc7 to your computer and use it in GitHub Desktop.
Save wojciak/18b661007b885912f60d8663561d4fc7 to your computer and use it in GitHub Desktop.
Array flatten
function flatten(arr) {
if (Array.flat) { // because we're all excited that this is finally making production!
return arr.flat(Infinity);
}
if (!arr.some(item => Array.isArray(item))) {
return arr;
}
return flatten([].concat(...arr));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment