Skip to content

Instantly share code, notes, and snippets.

@kunjee17
Created December 29, 2016 14:56
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 kunjee17/8eaa2a28dc7a8487f6b8bb60ca8ff558 to your computer and use it in GitHub Desktop.
Save kunjee17/8eaa2a28dc7a8487f6b8bb60ca8ff558 to your computer and use it in GitHub Desktop.
Javascript flatten array.
var test = [[1,2,[3]],4];
var result = [];
//[1,2,3,4]
var process = function(arr) {
arr.forEach(function(a){
if(Array.isArray(a)){
process(a);
}else {
result = result.concat(a);
}
});
}
process(test);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment