'How set conditions in column
I try to set brackets {} after the arrow function, but the result is ever null
return Array.from(columns, column => column.innerText);
I want to set something like this:
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;
});
Solution 1:[1]
Array.from expects returned values in the callback function, but you haven't returned anything from it
You can check these examples
No brackets - Returning column.innerText directly
return Array.from(columns, column => column.innerText); //correct
Brackets and no return (incorrect)
return Array.from(columns, column => {
column.innerText //incorrect
});
Brackets and a return (correct)
return Array.from(columns, column => {
return column.innerText //correct
});
For your case, you can modify it like this
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
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nick Vu |
