Skip to content

Instantly share code, notes, and snippets.

@gognjanovski
Created December 21, 2019 15:29
Show Gist options
  • Save gognjanovski/4427ca34b043c78f5db88f22c44038c7 to your computer and use it in GitHub Desktop.
Save gognjanovski/4427ca34b043c78f5db88f22c44038c7 to your computer and use it in GitHub Desktop.
var testArray = [[1,2,[3]],4];
function flat(array) {
var result = [];
for(var i=0; i < array.length; i++) {
if(array[i] instanceof Array) {
result.push(...flat(array[i]));
} else {
result.push(array[i]);
}
}
return result;
}
console.log(flat(testArray));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment