Reputation: 366
I'm confused about how to get a value out of the row2 array below. When I log the full array, as I've done in the code, I see all nine values listed that come from row two of the spreadsheet. However when I try to pull out the 9th value, also listed in the code, the result is undefined. Can anyone tell me why?
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // get the spreadsheet object
var reportConfig = spreadsheet.getSheetByName("Report Configuration"); // set report configuration sheet
var lastColumn = reportConfig.getLastColumn();
var lastColumnTitle = reportConfig.getRange(1,lastColumn).getValue();
var row2 = reportConfig.getRange(2,1,1,lastColumn).getValues();
Logger.log(row2);
Logger.log(row2[9]);
Upvotes: 0
Views: 65
Reputation: 27282
row2 will be a 2D-array, so row2[9] would refer to the 10th row in that array which doesn't exist. try: Logger.log(row2[0][9])
or change row2 to var row2 = reportConfig.getRange(2,1,1,lastColumn).getValues()[0]
and then do: Logger.log(row2[9])
Upvotes: 1