How do you reassign the value of an item in an array, that's within an array?
const clickedspaces = [
[0, 0],
[0, 0, 0],
[0, 0],
[0, 0, 0],
[0, 0],
];
clickedspaces[0[0]] = 1;
console.log(clickedspaces);
// What shows up in the console:
(5) [Array(2), Array(3), Array(2), Array(3), Array(2), undefined: 1]
0: (2) [0, 0]
1: (3) [0, 0, 0]
2: (2) [0, 0]
3: (3) [0, 0, 0]
4: (2) [0, 0]
undefined: 1
length: 5
__proto__: Array(0)
I'm trying to assign the value of the first integer there to 1.
clickedspaces[0]
The above code would target the first array [0, 0] but I don't know how you might target the first item in this array. Thanks.
Posted Oct 4, 2020, 12:33 AM UTC
clickedspaces[0][0] = 1;
Thank you very much!
You're no fun.
why?
Because giving straight answers doesn't teach people anything and it's boring.
Your answer moves the OP toward working code, which helps OP in the short term, but u/redsandfort's answer quickly and clearly demonstrates the problem with
clickedspaces[0[0]] = 1. What you see as giving a straight answer, I see as showing (i.e. teaching).I don't know why the syntax to do what I needed is that way, but now I do know how to do it at least.
Lol I like how you said it's boring. I find both approaches helpful where I have some basic knowledge on the topic. Thank you as well!