I wrote the following function which takes in a window and returns all nested windows on a webpage (I can get all the windows by calling the function with window.top). Is there a more elegant/efficient way to grab a reference to all the windows and child windows on the page? The function works, but I was having a hard time wrapping my head around writing it completely recursively (without the for loop) as the DOM tree is an n-ary tree, not binary.function getNestedWindows(window) {    var windows = [window];    if (window.length === 0) {      return windows;    }    else {      for (var i = 0; i < window.length; i++) {        windows = windows.concat(getNestedWindows(window[i]));      }    }    return windows;}
Function to grab all windows and nested windows on a page
javascript;dom