Created
January 13, 2018 06:02
-
-
Save nishant8BITS/f57e50cbd622be9f51a926adc810a9af to your computer and use it in GitHub Desktop.
Flatten javascript Array into a single-depth Array Raw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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