title: if (identical values between 2 array indices) { set data in corresponding spreadsheet }
body: <p>Summary of the script: Scrapes basic email information (date sent/received, to, from, subject, email label) and logs this data into spreadsheets. The spreadsheets are named after email labels, all emails that belong to a certain label get their information logged to that corresponding spreadsheet.</p>
  
  <p>The spreadsheet names and Ids are organized in the array of arrays <code>fileNames</code> as <code>[[spreadsheet name, id],[spreadsheet name, id],[etc, etc]]</code></p>
  
  <p>Below is some of this array setup.</p>
  
  <pre><code>function testFunction(){  
  
  var emailByLabel = ["just", "a", "list", "of", "data"];
  
   // ** CREATE AN ARRAY OF ARRAYS. 
   // LAYER 1- [LIST OF SPREADSHEETS]
   // LAYER 2- [SPREADSHEET NAME, SPREADSHEET ID]
   var fileNames = [];
   var folders = DriveApp.getFoldersByName("email-data");
  
   while (folders.hasNext()) {
       var folder = folders.next();
       var files = folder.getFiles();
     while (files.hasNext()) {
        var file = files.next();
        fileNames.push([file.getName(), file.getId()]);
     } 
   }
  </code></pre>
  
  <p>It is here that I am trying to "match" spreadsheet names to label names, and "set" data to corresponding spreadsheets when there's a match. Instead what I am getting is all data in all spreadsheets. </p>
  
  <pre><code>for(var l=0;l&lt;fileNames.length;l++){
      for(var i=0;i&lt;emailByLabel.length;i++){
        if(emailByLabel[i][1] == fileNames[l][0]){
  
          var ss = SpreadsheetApp.openById(fileNames[l][1]).getSheets()[0];
          Logger.log(fileNames[l][0]);
          Logger.log(fileNames[l][1]);
  
          ss.getRange(2,1,emailByLabel.length,5).setValues(emailByLabel);
  
        } else {
          Logger.log("MATCH, BROKE!");
          Logger.log(fileNames[l][0]);
          Logger.log(fileNames[l][1]);
        }
      }
    }
  }
  </code></pre>
  
  <p>I have tried replacing </p>
  
  <pre><code>    ss.getRange(2,1,emailByLabel.length,5).setValues(emailByLabel);
  </code></pre>
  
  <p>with </p>
  
  <pre><code>    ss.getRange(2,1,emailByLabel[i].length,5).setValues(emailByLabel[i]);
  </code></pre>
  
  <p>but i receive the error <code>Cannot convert Array to Object[][]</code></p>
  
  <p>Full Code with some highlighted, relevant lines of code: <a href="http://pastie.org/9793256#96,100,109,117,123-139" rel="nofollow">http://pastie.org/9793256#96,100,109,117,123-139</a></p>