Google Apps Script is raising an error when I try to access the nested array with double indexing, it says: TypeError: Cannot read property "3" from undefined. (line 27, file "Code")
Here is the code:
var ss = SpreadsheetApp.openById("SpreadsheetID");
var sheetMAT = ss.getSheetByName("Sheet3");
var data = sheetMAT.getRange(3, 2, sheetMAT.getLastRow() - 1, 4).getValues();
var temporaryData = [];
var dataReadyLine = [];
function getReadyLine() {
var rawData = sheetMAT.getRange(3, 2, sheetMAT.getLastRow() - 1, 4).getValues();
Logger.log(rawData[0][3]);
for (var i=0; i<=rawData.length; i++) {
if (rawData[i][3] === "A Ready Line") {
temporaryData.push(data[i][1], data[i][0]);
dataReadyLine.push(temporaryData);
temporaryData = [];
}
}
return dataReadyLine;
};
The line 'Logger.log(rawData[0][3]);' successfully prints the value of the nested array item but when it comes to IF conditional it gives the error of undefined. Why is it giving this error? How can i make the FOR loop work?
Here is the print screen with the error when I try to run the code: Print Screen