I am trying to remove certain children from DOM by iterating through them. I have a table, and I am looping through the children and removing some like this:
for (const row of table.children) {
const testRow = row.children[2];
if (testRow.textContent === "false") {
table.removeChild(row);
}
}
When this code is run, some of the children that meet the condition testRow.textContent === "false" are removed, but other rows that meet the condition are not removed.
Logging out t.children.lengh as the loop goes on reveals that the size is decreasing (due to the children being removed). My theory is that removing a child messes up the iterator. I tried rewriting this code as a for loop and got the same result: some children are "skipped over" and not removed.
Ideas on how to remove certain children of a DOM element (based on dynamically pulled data)?