title: How do I use setValues to paste the data I got from getValues? Google Spreadsheet
body: <p>I can't seem to wrap my head around 2D arrays. I have set up the following code. but I'm unable to get setValues to work (the end of the code.)</p>
  <p>I'm pretty sure I need to set it up as an array, but every way I've tried to set it up has resulted in a different error message. How do I properly set up the array so that all of the students' data for each class (k) gets sent to each class tab?</p>
  <pre><code>function onSearch() {
      var sheetID = DriveApp.getFilesByName('Dash').next().getId();
      var ss = SpreadsheetApp.openById(sheetID);
      var sheet = ss.getSheetByName(&quot;Master List&quot;);
      
      //Loop through Class List, get Course Codes
      var classes = ss
        .getSheetByName(&quot;sheetInfo&quot;)
        .getRange(1, 2, 3)
        .getValues();
    
      //Loop through courses
      for (var k = 0; k &lt; classes.length; k++) {
          var classCode = classes [k];
          var searchVal = classCode;
          var column = 18;
      
       //Get Course Sheets
           var classSheetArray = ss.getSheetByName(&quot;sheetInfo&quot;)
               .getRange(1, 1, 3)
               .getValues();
           var classSheetName = classSheetArray [k];
           var classSheet = ss.getSheetByName(classSheetName);
       
       //Insert headers into Class sheets
           sheet.getRange(1, 1, 1, 17).copyTo(classSheet.getRange(1, 1, 1,     17));
                                        
      //Loop through 9 different course codes from student timetable
      for (var j = 0; j &lt; 9; j++) {
                
          var searchCol = sheet.getRange(2, column+j, sheet.getLastRow())
            .getValues();  
        
              for (var i = 0, len = searchCol.length; i &lt; len; i++) {                                                       
                             
                  //Take the data from the search and place it in the   corresponding class tab. 
                  //This data will have 17 columns and the number of rows is   dependent on the number of returned students.
                  if (searchCol[i][0] == searchVal) {
                      var lastRow = classSheet.getLastRow();
                      var sourceInfo = sheet.getRange(i+2, 1, 1, 17)
                          .getValues();
                                      
                      tempArray = [];
                      tempArray.push(sourceInfo[i]);
                  
                      Logger.log(tempArray); // WHEN I LOG THE ARRAY THE DATA LOOKS LIKE [[col 1, col 2 ...]][[col 1, col 2 ...]]...
                  
                      classSheet.getRange(lastRow+1,1,1,sourceInfo.length) //DEFINITELY KNOW THIS TO BE WRONG...  
                          .setValues(tempArray[0][i]); 
                                                                
                  }
              }
          } 
      }
  }
  </code></pre>