Last active
January 5, 2021 20:20
-
-
Save jasonreiche/7a87bdd9bc9a2d20b448bde2f5b53fa3 to your computer and use it in GitHub Desktop.
Reduce a table to a maximum number of columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const maxCol = 2; | |
const table = document.querySelector("table#target"); | |
// Use an array spread to quickly iterate rows in table | |
[...table.getElementsByTagName("TR")].forEach(row => { | |
// delete all columns beyond max | |
while (row.children.length > maxCol) { | |
row.children[maxCol].remove(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment