title: Programmatically delete a Google Apps Script time-based trigger by trigger name?
body: <p>How can I programmatically delete a Google Apps Script time-based trigger by the triggered function's name, instead of triggerarray id?</p>
  
  <p>I am creating a trigger and later on I want to delete the trigger by name. I tried this:</p>
  
  <pre><code>ScriptApp.deleteTrigger("myfunction");
  </code></pre>
  
  <p>but it does not work. I don't want to use this method:</p>
  
  <pre><code>var triggers = ScriptApp.getProjectTriggers();
      ScriptApp.deleteTrigger(triggers[0]);
  </code></pre>
  
  <p>Since I have more than one trigger at same time and might delete the wrong one!
  So how to delete trigger by its name instead of trigger array id?</p>
  
  <pre><code>function demo(){
    ScriptApp.newTrigger("myfunction")
      .timeBased()
      .everyMinutes(1)
      .create(); 
    }
  
    function myfunction(){
      // do some stuff here then stop the trigger by name
      ScriptApp.deleteTrigger("myfunction");
    }
  }
  </code></pre>