I tried to deconstruct an array in a recursive method. Below is a simplefied example. Everything is working just fine.
function createNode(index, node) {
let next = node+ 1
if (next < 100) {
for (let i=0; i < 5; i++) {
[index, next] = createNode(index, next)
}
}
return [index, next]
}
createNode(0, 0)
However when I add console.log to the for loop it crashes.
for (let i=0; i < 5; i++) {
console.log(next)
[index, next] = createNode(index, next)
}
Uncaught TypeError: Cannot set property '99' of undefined
The problem isn't getting around it. I just want to understand and know what is causing it. I've been searching for a while now and to be honest, I have no idea yet.