0
如何獲得在Javascript如何獲得在二維數組單元格的值在Javascript
在二維數組單元格的值我有一個數字表,將31周的cols * 9行,我想要得到的細胞獲得現場功能的價值!所以我想要[1] [2]。對我來說重要的價值只有Y?如何將網格傳遞給點函數?此外,對於性能有任何建議將是非常美妙的,你可以看到的是巨大的數組
var cols = 31;
var rows = 9;
var theGrid = new Array(cols);
var i;
var j;
//get the spot
function getTheSpot(j, i) {
// when the col met the row it create a spot
//that what i need to get
this.y = i;
this.x = j;
return i;
return j;
}
//create a grid for the numbers
function createGrid() {
// BELOW CREATES THE 2D ARRAY
for (var i = 0; i < cols; i++) {
theGrid[i] = new Array(rows);
}
for (var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
theGrid[j][i] = new getTheSpot(j, i);
}
}
}
var s = getTheSpot(9, 2);
console.log (s);
你介意給我們展示你到目前爲止嘗試過什麼嗎? –