Search code examples
google-apps-scriptgoogle-forms

Google Scripts - Google Forms - Get Strings of Items


I am having some difficulty capturing the names of the items within my Google Form. I want to be able to store the form item names to then be used with if/else statements to better filter my responses. I am able to get the number of items within my form, but cannot pull the names of those form items. Can anyone help me figure out what method I'm missing?

  //Capture Questions 
  var items = form.getItems();

  //Capture Question Titles, Provides # of items in "[items, items, ...]" format
  var itemsTitle = items.toString();

//Does nothing
var titles = itemsTitle.getTitle();

Solution

  • .getTitle() has to be called on an item object, not a string:

    for ( var i in items ) {
      var title = items[i].getTitle()
    }
    

    or items[0].getTitle() if you know the exact index of the item