So I've read many problems on here about people losing their variable's value, and it has something to do with closure. But I am completely unable to identify the problem here. I've tried with for loops, while loops, neither works.
function parseArray(arrayIn) {
var firstRow = arrayIn.shift();
while ( arrayIn.length > 0 ) {
addToTable(firstRow, arrayIn.shift());
}
}
I've also tried
function parseArray(arrayIn) {
var firstRow = Object.assign([], arrayIn[0]);
for ( var i=1; i<arrayIn.length; i++) {
addToTable(firstRow, arrayIn[i]);
}
}
Either way, addToTable is called twice correctly, and on the third pass, firstRow is an empty array. I originally tried sending arrayIn[0] which also became an empty array on the third pass. The strangest thing is, the second value (arrayIn.shift() or arrayIn[i]) is the correct and expected value the whole time.
This is probably something simple I'm just missing, but, can anyone help? I've been unable to see how other answers to do with closure apply to this case.