2D array issues in Google Scripts / Javascript -




i have code retrieves data google sheet. loop through data dates equal today's date only. want put values sheet. i'm not understanding how 2d arrays work... below have far. know loop find today's entries working. not sure i'm doing wrong though. appreciated. n variable returns correct number of rows should in array. however, row , column count not correct. sheet i'm reading data has 4 columns. need 3 of them though.

var ss = spreadsheetapp.getactive(); var sheet = ss.getsheetbyname('edit info'); var rows = sheet.getdatarange(); var values = rows.getvalues();  logger.log(values.length) logger.log(values[0].length)  var todayvalues = []; var todvalues = ""; var rowvalues = [];  var today = new date(); var dd = today.getdate(); var mm = today.getmonth()+1; //january 0! var yyyy = today.getfullyear();  if(dd<10) { dd = '0'+dd }   if(mm<10) { mm = '0'+mm }    today = mm + "/" + dd + "/" + yyyy; logger.log("today: " + today) var n = 1; for(var = 1; < values.length; i++) {    var formatteddate = values[i][0]; var newdate = utilities.formatdate(new date(formatteddate), "gmt-6",  "mm/dd/yyyy"); //logger.log("newdate: "+newdate) if(newdate == today){    //todvalues += values[j][0] + "," + values[i][3] + "," + values[i][2];   todayvalues.push(values[i][0], values[i][3], values[i][2]);   n = n + 1   logger.log(values[i][0] + ", " + values[i][3] + ", " + values[i][2]) } }  logger.log("n row count: " + n) //how many times date  found logger.log("rows: " + todayvalues.length) logger.log ("columns: " + todayvalues[0].length) 

have used debug option in script editor. see troubleshooting page use if have not. easier using logs.

when should find retrieved data saved values different data saved todayvalues. simplified, this:

values  [["a", "b", "c"],["d", "e", "f"]] todayvalues  ["a", "b", "c","d", "e", "f"] 

note additional square brackets in values.

you want code in loop read

 todayvalues.push([values[i][0], values[i][3], values[i][2]]); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -