我尝试在箭头函数之后设置括号{},但结果总是为空
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
期望在回调函数中返回值,但是您还没有从中返回任何值
你可以查看这些例子
没有括号-直接返回column.innerText
return Array.from(columns, column => column.innerText); //correct
括号和不返回(不正确)
return Array.from(columns, column => {
column.innerText //incorrect
});
括号和返回符(正确)
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
});