title: Getting groups of unknown depths - group.getDepth, group.getRowGroup
body: <p>I would like the GAS code to get the depth of the group that starts at a given Row number.</p>
  
  <p>The dirty way to do this would be to write the depth of the group into a hidden column when I create the group, but is there a way to find the depth of a group at a given row programmatically? the Demo code for get group depth in the documentation is this:</p>
  
  <pre><code>var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  var range = sheet.getRange(2:3);
  range.shiftRowGroupDepth(1);
  var group = sheet.getRowGroupAt(2, 1);
  
  // Returns 1 if the group is at depth 1.
  var depth = group.getDepth();
  </code></pre>
  
  <p>But that code required the depth in line 4 to GET the group it is asking the depth for. Which seems to negate any usefulness of the getDepth function.</p>
  
  <p>The ultimate goal is a function that can strip all the existing groups off the page, and another function that can collapse all the groups. But for either of those things I seem to need to know the dept in order to getRowGroup them.</p>