Skip to content

Instantly share code, notes, and snippets.

@nishant8BITS
Created January 13, 2018 06:02
Show Gist options
  • Save nishant8BITS/f57e50cbd622be9f51a926adc810a9af to your computer and use it in GitHub Desktop.
Save nishant8BITS/f57e50cbd622be9f51a926adc810a9af to your computer and use it in GitHub Desktop.
Flatten javascript Array into a single-depth Array Raw
function flattenArray(array){
const toFlatterArray = [];
if(Array.isArray(array)){
array.map((elm)=>{
if(Array.isArray(elm)){
const arrayList = flattenArray(elm);
arrayList.map((_elm)=>{
toFlatterArray.push(_elm);
});
}else{
toFlatterArray.push(elm);
}
});
}
return toFlatterArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment