I'm trying to loop through an array of array, after each iteration, recursively call the function to loop through the arrays again, but one position further along the array of arrays. Code example below. Temp rows is just an example, the data could change and contain more or less arrays inside the outer array. Is there a way to do it without flattening the array?
tempRows = [[1,1,1],
[1,1,1],
[1,1,1]
]
num = 10;
func(start) {
for (let i = 0; i < tempRows.length; i++) {
for (let j = start; j < tempRows[i].length; j++) {
console.log(start) // start is now one element forward
//then loop through the rest of the elements as usual
}
}
if ( start < num) {
func(start + 1)
}
return;
}
func(0)