I have an array with several values and I want to get value stored in the multiple of 3. So, in this case the new array should be 13 and 28. However, I'm only getting 13.
Code:
// array1 --> [ '5', '10', '13', '15', '20', '28' ]
var trueLength = array1.length;
var iCount = 1;
for(var i = 0; i < trueLength;) {
if(iCount % 3 != 0) {
array1.shift();
} else if (iCount % 3 == 0) {
array2.push(array1[i]);
array1.shift();
}
iCount += 1;
if(iCount == trueLength) break;
}
Output:
[ '13' ]
I don't see anything logically wrong for it to only output 13 which makes no sense.