Skip to content

Instantly share code, notes, and snippets.

@ohhskar
Created April 16, 2020 15:23
Show Gist options
  • Save ohhskar/7cb8485222d1df74712a06f88e710c01 to your computer and use it in GitHub Desktop.
Save ohhskar/7cb8485222d1df74712a06f88e710c01 to your computer and use it in GitHub Desktop.
Flatten the children of two or more NodeLists into an array
// Magic code to flatten the children of two or more nodelists.
// [...sides] converts the two nodelists into two arrays. this is then
// mapped to get the children. [...element.children] gets the children of each
// side, but in the form of an array. This is done so that there will be n arrays
// that is composed of the children, this is then flattened
const getChildren = (sides) => [...sides].map((element) => [...element.children]).flat();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment