正在初始化当前对象,并为sth代码提供了一个示例:mycoldata=cell.innerHTMLIs,甚至JavaScript?因为您的for循环看起来有点像PHP。当您知道要查找什么时,许多语言惊人地相似。PHP会在每个变量前面使用$,但事实并非如此。

正在初始化当前对象,并为sth代码提供了一个示例:mycoldata=cell.innerHTMLIs,甚至JavaScript?因为您的for循环看起来有点像PHP。当您知道要查找什么时,许多语言惊人地相似。PHP会在每个变量前面使用$,但事实并非如此。,javascript,Javascript,正在初始化当前对象,并为sth代码提供了一个示例:mycoldata=cell.innerHTMLIs,甚至JavaScript?因为您的for循环看起来有点像PHP。当您知道要查找什么时,许多语言惊人地相似。PHP会在每个变量前面使用$,但事实并非如此。var也是JavaScript使用的一个关键字,而不是PHP,尽管如果他们添加了它,我可能会错过它。-编辑-没有输入换行符。。。正如我所说:逻辑是普遍的。知道如何将其转录成其他语言是一项非常有用的技能,这并不难学——我们是具有优秀模式匹配能力的


正在初始化当前对象,并为sth代码提供了一个示例:mycoldata=cell.innerHTMLIs,甚至JavaScript?因为您的for循环看起来有点像PHP。当您知道要查找什么时,许多语言惊人地相似。PHP会在每个变量前面使用$,但事实并非如此。var也是JavaScript使用的一个关键字,而不是PHP,尽管如果他们添加了它,我可能会错过它。-编辑-没有输入换行符。。。正如我所说:逻辑是普遍的。知道如何将其转录成其他语言是一项非常有用的技能,这并不难学——我们是具有优秀模式匹配能力的智力生物。识别每种语言之间的变化,或者简单地使用lexer语言定义…如果你回答的是一个问题
#行
什么都不说。。。请用完整的代码更新你的答案。请注意循环中的“for…of”。如果能在你的回答中有一些解释就好了。未捕获类型错误:无法读取未定义-->的属性“toArray”。这是我尝试此解决方案时得到的结果。奇怪。我又试了一次,成功了。不过,我无法重现你指出的错误。也许问题出在浏览器上。我使用Edge和IE进行了测试,但都不起作用。Chrome、Firefox和Safari都按预期运行。我也使用了Chrome。这对我来说也适用。
Object.defineProperty
显然必须先于代码的其余部分,但它是有效的@Vineela Thunupunuri您是否按照正确的顺序使用代码进行了尝试?
<div id="myTabDiv">
<table name="mytab" id="mytab1">
  <tr> 
    <td>col1 Val1</td>
    <td>col2 Val2</td>
  </tr>
  <tr>
    <td>col1 Val3</td>
    <td>col2 Val4</td>
  </tr>
</table>
</div>
var table = document.getElementById("mytab1");
for (var i = 0, row; row = table.rows[i]; i++) {
   //iterate through rows
   //rows would be accessed using the "row" variable assigned in the for loop
   for (var j = 0, col; col = row.cells[j]; j++) {
     //iterate through columns
     //columns would be accessed using the "col" variable assigned in the for loop
   }  
}
var table = document.getElementById("mytab1");
for (var i = 0, cell; cell = table.cells[i]; i++) {
     //iterate through cells
     //cells would be accessed using the "cell" variable assigned in the for loop
}
$('#mytab1 tr').each(function(){
    $(this).find('td').each(function(){
        //do your stuff, you can use $(this) to get current cell
    })
})
var table = document.getElementById("myTable").rows;
var y;
for(i = 0; i < # of rows; i++)
{    for(j = 0; j < # of columns; j++)
     {
         y = table[i].cells;
         //do something with cells in a row
         y[j].innerHTML = "";
     }
}
for (let row of mytab1.rows) 
{
    for(let cell of row.cells) 
    {
       let val = cell.innerText; // your code below
    }
}
    const table = document.getElementById("mytab1");
    const cells = table.rows.toArray()
                  .flatMap(row => row.cells.toArray())
                  .map(cell => cell.innerHTML); //["col1 Val1", "col2 Val2", "col1 Val3", "col2 Val4"]
    Object.defineProperty(HTMLCollection.prototype, "toArray", {
        value: function toArray() {
            return Array.prototype.slice.call(this, 0);
        },
        writable: true,
        configurable: true
    });
var t = document.getElementById('mytab1');
if(t) {
    Array.from(t.rows).forEach((tr, row_ind) => {
        Array.from(tr.cells).forEach((cell, col_ind) => {
            console.log('Value at row/col [' + row_ind + ',' + col_ind + '] = ' + cell.textContent);
        });
    });
}
var table = document.getElementById('tableID');  
var count = table.rows.length;  
for(var i=0; i<count; i++) {    
    console.log(table.rows[i]);    
}
//select what table you want to scrape (is zero based)
//set 0 if there is only one
setTable=0;
//select what column you want to scrape (is zero based)
//in this case I would be scrapping column 2
setColumnToScrape=1;
var table = document.getElementsByTagName("tbody")[setTable];
for (var i = 0, row; row = table.rows[i]; i++) {
  col = row.cells[setColumnToScrape];
  document.write(col.innerHTML + "<br>");
}
    <script>
        var tab = document.getElementsByTagName("table")
        for (var val of tab[0].childNodes[1].childNodes.values())
            if (HTMLCollection.prototype.isPrototypeOf(val.children)) {
                for (var i of val.children) {
                    console.log(i.childNodes[0])
                }
            }
    </script>