如何在列中设置条件

How set conditions in column

我尝试在箭头函数后面设置括号{},但结果总是空的

return Array.from(columns, column => column.innerText);

我想这样设置:

return Array.from(rows, row => {
            const columns = row.querySelectorAll('td');
            return Array.from(columns, column => {
                if(column.href.includes('new-york-time')){
                    console.log('well link')
                }
                column.innerText;
                });

Array.from 期望在回调函数中 returned 值,但你还没有 returned 任何东西

您可以查看这些示例

没有括号 - 直接返回 column.innerText

return Array.from(columns, column => column.innerText); //correct

没有括号 return(不正确)

return Array.from(columns, column => {
  column.innerText //incorrect
});

括号和一个return(正确)

return Array.from(columns, column => {
  return column.innerText //correct
});

对于你的情况,你可以这样修改

return Array.from(rows, row => {
            const columns = row.querySelectorAll('td');
            return Array.from(columns, column => {
                if(column.href.includes('new-york-time')){
                    //TODO: Do something with your condition
                    console.log('well link')
                }
                return column.innerText; //return here
            });