title: TypeError: Cannot call method "getName" of undefined
body: <p>i've been coding this:</p>
  
  <pre><code>    function deleteSheets(){
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheets = ss.getSheets();
  
  
    for(var i = 0; i&lt;=sheets.length; i++){
  
      var name = sheets[i].getName();
  
      if (name == "aux"){
        ss.deleteSheet(sheets[i]);
      }else if(name == "nulos"){
  
        ss.deleteSheet(sheets[i]);
  
        }
  
  
  
      /* switch(sheets[i].getName()){
  
        case sheets[i].getName() == "aux":
          ss.deleteSheet(sheets[i]);
          break;
  
        case sheets[i].getName() == "nulos":
          ss.deleteSheet(sheets[i]);
          break;
  
        case name == "aux":
          ss.deleteSheet(sheets[i]);
          break; 
    }
  
    */
  
  }
  
  }
  </code></pre>
  
  <p>Tried to do a simple "deleteSheet" with switch, which didn't work, then with a if just to see the same error: </p>
  
  <blockquote>
    <p>TypeError: Cannot call method "getName" of undefined. (line 8, file "Code")</p>
  </blockquote>
  
  <p>What am I missing? Pretty sure i've already done a similar thing before...
  (If it's obvious, i'm sorry, i'm noob)</p>