Javascript 为什么多维数组中的最后一个元素不可查找?

Javascript 为什么多维数组中的最后一个元素不可查找?,javascript,Javascript,名字 姓 年龄 var anArray=[[“A1”、“B1”、“C1”], [“A2”、“B2”、“C2”], [“A3”、“B3”、“C3”], [“A4”、“B4”、“C4”], [“A5”、“B5”、“C5”], [“A1”、“B1”、“C1”], [“A2”、“B2”、“C2”], [“A3”、“B3”、“C3”], [“A4”、“B4”、“C4”], [“A5”、“B5”、“C5”]//数组的最后一个元素不可勾选,我假设数组的最后一个元素为空?要单击数组的最后一个元素,我将做什


名字
姓
年龄

var anArray=[[“A1”、“B1”、“C1”],
[“A2”、“B2”、“C2”],
[“A3”、“B3”、“C3”],
[“A4”、“B4”、“C4”],
[“A5”、“B5”、“C5”],
[“A1”、“B1”、“C1”],
[“A2”、“B2”、“C2”],
[“A3”、“B3”、“C3”],
[“A4”、“B4”、“C4”],
[“A5”、“B5”、“C5”]//数组的最后一个元素不可勾选,我假设数组的最后一个元素为空?要单击数组的最后一个元素,我将做什么?
var tables=document.getElementById(“表格”);
对于(变量i=0;i

我做了我能做的一切,我想在javascript上创建一个多维数组列表,同时在HTML上打印输出,单击表格单元格,我做到了,但出现了一个问题:anArray的最后一个元素变成了null,因为它不可勾选。我做错了什么?有什么建议吗?

问题是您的表格顶部多了一行,如下所示:

        var anArray = [["A1","B1","C1"],
                     ["A2","B2","C2"],
                     ["A3","B3","C3"],
                     ["A4","B4","C4"],
                     ["A5","B5","C5"],
                     ["A1","B1","C1"],
                     ["A2","B2","C2"],
                     ["A3","B3","C3"],
                     ["A4","B4","C4"],
                     ["A5","B5","C5"]]; //last element of array was unclickable, I assumed that the last element of the array was null? what will I do to click the last element of array?

            var tables = document.getElementById("table");




       for(var i = 0; i < anArray.length; i++)
       {
           // create a new row
           var newRow = table.insertRow(tables.length);

            console.log(newRow);
           for(var j = 0; j < anArray[i].length; j++)
           {
               // create a new cell
                cell = newRow.insertCell(j);

               // add value to the cell
               cell.innerHTML = anArray[i][j];

            tables.rows[i].cells[j].onclick = function(){

            rIndex = this.parentElement.rowIndex+1;
                    cIndex = this.cellIndex;
                    console.log("Row : "+rIndex+" , Cell : "+cIndex);







                }

               }
           }

名字
姓
年龄

我的朋友,你是个巫师,但我没有注意到这一点。谢谢你纠正我的错误:D
        var anArray = [["A1","B1","C1"],
                     ["A2","B2","C2"],
                     ["A3","B3","C3"],
                     ["A4","B4","C4"],
                     ["A5","B5","C5"],
                     ["A1","B1","C1"],
                     ["A2","B2","C2"],
                     ["A3","B3","C3"],
                     ["A4","B4","C4"],
                     ["A5","B5","C5"]]; //last element of array was unclickable, I assumed that the last element of the array was null? what will I do to click the last element of array?

            var tables = document.getElementById("table");




       for(var i = 0; i < anArray.length; i++)
       {
           // create a new row
           var newRow = table.insertRow(tables.length);

            console.log(newRow);
           for(var j = 0; j < anArray[i].length; j++)
           {
               // create a new cell
                cell = newRow.insertCell(j);

               // add value to the cell
               cell.innerHTML = anArray[i][j];

            tables.rows[i].cells[j].onclick = function(){

            rIndex = this.parentElement.rowIndex+1;
                    cIndex = this.cellIndex;
                    console.log("Row : "+rIndex+" , Cell : "+cIndex);







                }

               }
           }
<tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Age</th>
</tr>