Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AliceWonderland/2c22a33b2e1e7db7c61f6a9ebc185e4e to your computer and use it in GitHub Desktop.

Select an option

Save AliceWonderland/2c22a33b2e1e7db7c61f6a9ebc185e4e to your computer and use it in GitHub Desktop.
4.4 Array Flattener created by smillaraaq - https://repl.it/GzQT/1
function flatten(argArray){
var newArray=[];
for(i=0;i<argArray.length;i++){
if(typeof argArray[i]==="object"){
for(x=0;x<argArray[i].length;x++){
newArray.push(argArray[i][x]);
}
}else{
newArray.push(argArray[i]);
}
}
console.log(newArray);
}
flatten([1,[2,3],4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment