I have problem with editing fetched values

26 Views Asked by At

When I extract data and want to add them to table, the given JavaScript code only retrieves the first row from each <td> and ignores the rest. This is a problem because I don't know how to make it retrieve all rows for the second, third, and fourth <td> and add them as new thing separatly when they start with "-" sign. In first <td> i need only "Title 1". I would greatly appreciate your help.

JavaScript:

const dataSets = [{ set: new Set(), columnIndex: 0 }, { set: new Set(), columnIndex: 1 }, { set: new Set(), columnIndex: 2 }, { set: new Set(), columnIndex: 3 }];
const tbody = document.querySelector("tbody");
const rows = tbody.querySelectorAll("tr");


for (let row of rows) {
    const cells = row.querySelectorAll("td");
    for (let dataSet of dataSets) {
        const cell = cells[dataSet.columnIndex];
        if (cell) {
            dataSet.set.add(cell.innerText.trim().split('\n')[0]);
        }
    }
}

HTML:

        <tr>
          <td>Title 1<br />
          Line title 1
          </td>
          <td>Specific 1</td>
          <td>- Thing 1<br />
          - Thing 2
          </td>
          <td>- Something 1<br />
          - Something 2<br />
          - Something 3<br />
          - Something 4<br />
          - Something 5<br />
          - Something 6<br />
          - Something 7
          </td>
        </tr>
0

There are 0 best solutions below