I'm trying to add a unique ID to a bunch of array items in my project but came across an extremely weird issue that I cannot seem to reproduce in CodeSandbox. It seems to be unique to my project.
weekarr.forEach((a, q) => {
a.forEach((b, w) => {
console.log(`${q} + ${w}`);
b.id = `${q} + ${w}`;
});
});
This is the loop that I am running. In the console you see this:
0 + 0
0 + 1
0 + 2
0 + 3
0 + 4
0 + 5
0 + 6
0 + 7
0 + 8
0 + 9
0 + 10
0 + 11
1 + 0
1 + 1
1 + 2
1 + 3
1 + 4
1 + 5
1 + 6
1 + 7
1 + 8
1 + 9
1 + 10
1 + 11
2 + 0
2 + 1
2 + 2
2 + 3
2 + 4
2 + 5
2 + 6
2 + 7
2 + 8
2 + 9
2 + 10
2 + 11
3 + 0
3 + 1
3 + 2
3 + 3
3 + 4
3 + 5
3 + 6
3 + 7
3 + 8
3 + 9
3 + 10
3 + 11
That's completely perfect. But when I go ahead and check b.id in every array. This is what I see for the first array of each of every array:
3 + 0
3 + 0
3 + 0
3 + 0
This is what it should have been instead:
0 + 0
1 + 0
2 + 0
3 + 0
I cannot seem to be able to reproduce this problem in anyway. It only seems to happen with the particular array that I made. I've tried to push the array into a fresh empty array and the problem still stays. I'm not sure if it's React causing this, or some weird javascript bug. Can anyone help me?
EDIT: Picture of the array: