Skip to content

Instantly share code, notes, and snippets.

@jadeallencook
Created May 22, 2019 01:08
Show Gist options
  • Save jadeallencook/8441a399627e10c17a805386d92c0db9 to your computer and use it in GitHub Desktop.
Save jadeallencook/8441a399627e10c17a805386d92c0db9 to your computer and use it in GitHub Desktop.
Recursive ES6 function that flattens an array.
const flatten = array => array.reduce((temp, value) => temp.concat(Array.isArray(value) ? flatten(value) : value), []);
// example
console.log(flatten([[['str']],undefined,null,{},[[true,false],[{},[]],[],{}],[],[],[],[]]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment