My array looks like this:
arrayA = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2];
I want to organize the numbers into groups like this:
arrayB = [1234,5678,9123,4567,8912];
Essentially, I need to take the values from arrayA and create new numbers by grouping 4 numbers together.
My current code has a bug where the output looks like this:
arrayB=[undefined1234,undefined5678];
This is the code I used:
for (var i = 0; i < 20; i++) {
if (i/4== n+1){
arrayB[n] = temp;
n++;
}
temp += arrayA[i];
}
I recognize that the bug is due to the +=
operator, but I'm unsure how to resolve it.