I am trying to create a for
loop that simultaneously iterates through two variables. One is an array named n
, and the other, j
, ranges from 0 to 16.
var n = [1,2,3,5,7,8,9,11,12,13,14,16,17,18,20,21,22];
var m = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
m.forEach(k => {
n.forEach(i => {
console.log(i, k)
});
};
The expected output should be:
1,0
2,1
3,2
5,3
(...)
However, the current loop iteration seems to repeat every number 17 times instead of sequentially pairing each element as intended.
Can someone help point out where the issue lies?