title: How to Iterate to output data to Google Sheets with App-Script
body: <p>Using Google App Script, when I used Logger.log() the for loop iterates properly and I get results for each value. When I try to output this to a google sheet only the last value for each variable is output over and over again for the number of goals.length.</p>
  
  <p>Any help is very much appreciated!</p>
  
  <pre><code>function listGoals() {
        var sheet = SpreadsheetApp.getActiveSheet();
        var filterList = Analytics.Management.Goals.list(accountId, webPropertyId, profileId)
        var goals = filterList.items;
          for (var i = 0, goal; goal = goals[i]; i++) {
              var accountId = goal.accountId;
              var propertyId = goal.webPropertyId;
              var goalNumber = goal.id;
              var goalName = goal.name;
  
              Logger.log('accountId: ' + accountId);
              Logger.log('profileId: ' + propertyId);
              Logger.log('goal number: ' + goalNumber);
              Logger.log('goal name: ' + goalName);
              //Logger.log prints for each result
  
              sheet.getRange(1,1,goals.length).setValue(goalNumber);
              sheet.getRange(1,2,goals.length).setValue(goalName);
              //this only prints out the last value of goalNumber and goalName to the sheet
  
          }
      }
  </code></pre>