Let's say I have a bunch of arrays named a=[], b=[], c=[], d=[], and so on. A Table is shown to the client and depending on the cell that the client clicks, we do operations to the specific array made for that cell. The code explains what I mean in a better way. I would be thankful if anyone helps. HTML:
<td id="block1" class="blocks" onclick="markNLock('a',this)" onmouseover="setMouseOverColor(this)" onmouseout="setMouseOutColor(this)">
Js:
function markNLock(idx, mark) {
for(var i=0; i<Matrix.length; i++)
{
Matrix[i] += idx[i];
console.log(idx[i]);
}
}
1 Answer 1
Notwithstanding the other advice I've given, the most expedient fix for your problem is not to use separate arrays, but to use your strings a, b etc as keys into the lookup matrix:
const game_matrix = {
'a': [1, 1, 0, 0, 1, 0, 0, 0],
'b': [0, 1, 0, 0, 0, 1, 0, 0],
...
}
and you can then use your string parameter as an index into that object:
Matrix[i] += game_matrix[idx][i];
addEventListenerinstead this problem won't happen.ainstead of"a". Problem solved