Skip to content

Instantly share code, notes, and snippets.

@arun057
Created February 25, 2019 22:45
Show Gist options
  • Save arun057/dc086bc4a5b237f8cdd2172789a601fc to your computer and use it in GitHub Desktop.
Save arun057/dc086bc4a5b237f8cdd2172789a601fc to your computer and use it in GitHub Desktop.
Flatten Array
function flattenArray(inputArray) {
var resultArray = [];
for (var i = 0; i < inputArray.length; i++) {
if (typeof(inputArray[i]) == 'number') {
resultArray.push(inputArray[i]);
} else if (Array.isArray(inputArray[i])) {
resultArray = resultArray.concat(flattenArray(inputArray[i]))
}
}
return resultArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment