Hello,
I have attempted to make a function that will raise each element in my nested array by one level. I think I have done it, however I am getting many returns of ‘undefined’. The pattern sequence of ‘undefined’s’ equates to how my nesting is arranged (3 UD, 3 UD, 5UD, 5UD, 5UD, 4UD), but I do not understand what operation even happened to create returns like this.
Thanks in advance
const arr2 = [[11, 12, 13], [14, 15, 16], [17], [18], [19], [[110], [111, [112, 113]]]];
function flattenArrayByOne(arrayOfArrays) {
const levelUp = [];
for (let i = 0; i < arrayOfArrays.length; i++) {
for (let j = 0; j < arrayOfArrays.length; j++) {
levelUp.push(arrayOfArrays[i][j]);
}
}
return levelUp;
}
console.log( flattenArrayByOne(arr2) );