Created
December 6, 2016 10:35
-
-
Save rajkumarpb/c21a7970dca88ae3afd6283b2ca8950d to your computer and use it in GitHub Desktop.
Flat an array of arrays
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
var inArr = [[[1, 2],],[3],[[4, 5],[6]]]; | |
var result = []; | |
function flattenArray(arr) { | |
for (var i = 0; i < arr.length; i++) { | |
if (Array.isArray(arr[i])) | |
flattenArray(arr[i]); | |
else | |
result.push(arr[i]); | |
} | |
return result; | |
} | |
alert(flattenArray(inArr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment