title: How to define array
body: <p>I get error that "cannot set property xx of undefined to xx"   when try to save a value to a multidimensional array. I had this code working a few weeks ago and now it doesn't.    I am not sure what changed but I believe the error is related t how the array is defined.</p>
  
  <pre><code>function iterateSheets() 
  {
    var ss=SpreadsheetApp.getActive();
    var folder=DriveApp.getFolderById('1ezdV7AHBNyq6aZdqKdvhlOhKMmLPhQoW');//replace id with actual id of folder
    var files=folder.getFilesByType(MimeType.GOOGLE_SHEETS);
    var consol_sheet = SpreadsheetApp.openById('1FyuizUjU8W8idMonEp0qFthvTDjfwmnboZivAAozDXU').getActiveSheet();
    consol_sheet.clear()
    var x=0;
    var z=0;
    var final_values = [[]];
  
  while(files.hasNext())
   {
      var file=files.next();
      var ts=SpreadsheetApp.openById(file.getId());
      var allShts=ts.getSheets();
  
  
         for(var i=0;i&lt;1;i++)   
         {  
          // if (allShts[i] == "Aug"  || allShts[i] = "Sept")
           //{   
              var consol_values = allShts[i].getRange(8,1,allShts[i].getLastRow(),10).getValues(); 
              var headers = allShts[i].getRange(4,6,1,4).getValues();  
              var position= allShts[i].getRange("B1").getValue();
              var period = allShts[i].getRange("B2").getValue();
              var email = allShts[i].getRange("B3").getValue();    
  
               for (var z = 0;z&lt;3;z++)//
               {   
  
                 for (var y= 0;y&lt;allShts[i].getLastRow();y++)               
                 {          
                   if (consol_values[y][0] != "" &amp;&amp; consol_values[y][z+5] !="")     
  
  
                   final_values[x] = [];       
  
                   final_values[x][0]  = consol_values[y][0]  //AI pack 
                   final_values[x][1]  = '1111'
                   final_values[x][2]  = consol_values[y][2]  ; //measure
                   final_values[x][3]  = email ;
                   final_values[x][4]  = position ;     
                   final_values[x][5]  = headers[0][z];//location
                   final_values[x][6]  = 1;
                   final_values[x][7]  = period;
                   final_values[x][8]  = consol_values[y][3]; //price
                   final_values[x][9]  = consol_values[y][z+5]; //fcst
  
                   if (consol_values[y][z+5] != "")
                   { 
                      final_values[x][10] =(consol_values[y][25]); //fcst value             
                   }                          
  
                   x = Number(x)+1  //row count for consolidation output
  
                  }
                //}   
  
           }    
        }
  
   }
  
  
  //consol_sheet.getRange(2,1,final_values.length,final_values[0].length).setValues(final_values);
  
  }
  </code></pre>
  
  <p>Any help in what I am doing wrong is much appreciated.</p>