Skip to content

Instantly share code, notes, and snippets.

@ghostffcode
Created October 7, 2016 00:23
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 ghostffcode/551b148295a99b19b60f6c0b927181f1 to your computer and use it in GitHub Desktop.
Save ghostffcode/551b148295a99b19b60f6c0b927181f1 to your computer and use it in GitHub Desktop.
var arr = [1,2, 3, [4,5,6, [45,26,25,89]], 7,8,9]
function flatten(myArray) {
return myArray.reduce(function (x, y) {
return x.concat(Array.isArray(y) ? flatten(y) : y);
}, []);
}
console.log(flatten(arr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment