title: Is there a way to use a loop to set choices in a list item in google forms scripts?
body: <p>I have a program I'm trying to make that takes the data in a spreadsheet and makes it into a google form and currently Im trying to make the 11 cells each populate one drop down list. there is the setChoices method and inside of it you createChoices but you cant have any other kind of code inside it to say make 11 Choices with a for loop each one being the next string in an array. If you can think of any other methods please let me know...</p>
  
  <p>This is my code currently:</p>
  
  <pre><code>function onOpen() {
    var sheet = SpreadsheetApp.getActiveSheet();
  
    var names = sheet.getRange(1, 1, 200);
  
    var values = names.getValues();
  
    var number = 0
  
    var count = 0;
  
    var array = "'" + values[0] + "'";
  
    while (values[count] != "") {
      number++;
      count++;
      if (values[count] != "") {
        array = array + ", " + "'" + values[count] + "'";
      }
    }
  
    Logger.log(number);
    Logger.log(array);
    for (var i = 0; i &lt; number; i++) {
      Logger.log(values[i]);
  
    }
  
    var form = FormApp.create("Cleaners");
  
    var formid = form.getId();
  
    var dropdown1 = form.addListItem();
  
    dropdown1.setTitle("Choose a Cleaner:");
  
    dropdown1.setChoices([
      dropdown1.createChoice(values[0]),
      dropdown1.createChoice(values[1]),
      dropdown1.createChoice(values[2]),
      dropdown1.createChoice(values[3]),
      dropdown1.createChoice(values[4]),
      dropdown1.createChoice(values[5]),
      dropdown1.createChoice(values[6]),
      dropdown1.createChoice(values[7]),
      dropdown1.createChoice(values[8]),
      dropdown1.createChoice(values[9]),
      dropdown1.createChoice(values[10])
    ]);
  
  }
  </code></pre>
  
  <p>When I make the dropdown I dont want to have to go in and change the amount of choices created if another name is added to the list.</p>