Skip to content

Instantly share code, notes, and snippets.


Emiliano Qaqi emiliano1

  • Miami, Florida
View GitHub Profile
View flatten_array.js
// recursive function to flatten an n-level deep array
function flattenArray(array, result = []) {
var arrayLength = array.length;
for (var i = 0; i < arrayLength; i++){
if (array[i] instanceof Array) {
// if item is an Array, call the function recursevely
result.concat(flattenArray(array[i], result));
} else {
// if item is not an Array, simply add it to final result