Skip to content

Instantly share code, notes, and snippets.

@jasonreiche
Last active January 5, 2021 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonreiche/7a87bdd9bc9a2d20b448bde2f5b53fa3 to your computer and use it in GitHub Desktop.
Save jasonreiche/7a87bdd9bc9a2d20b448bde2f5b53fa3 to your computer and use it in GitHub Desktop.
Reduce a table to a maximum number of columns
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