i am a javascript newbie. I have a 9*9 grid for my sudoku game. The html is such that each box of the grid is an inputelement with id like r1c4 where 1 is the row number and 4 is column number. I have half filled grid.I needed to store all the numbers in the grid in a two dimensional array.I have created the following function fo:
function getValues(){
var grid = new Array();
var colData = new Array();
var targetId;
for(var i=1;i<=9;i++)
{
for(var j=1;j<=9;j++)
{
targetId = 'r' + i + 'c' + j;
colData[j-1] = document.querySelector('#'+targetId).value;
}
grid[i-1] = colData;
console.log(grid[i-1]); // here logged correctly
}
return grid; // here returned wrong
}
The problem i am facing is that the returned array consists of only the last element repeated 9 times. I am logging the stored value every time by using console.log(grid[i-1]); and it is giving correct results.I am not getting it.
Regards.