When I run my script, I get this error message:
Syntax error: TypeError: Cannot read property “1” from undefined. line: ?
This is a snippet of my script:
var posConts = new Array();
var posContsData = SpreadsheetApp.openById(dataSheetValuesID).getSheets()[0].getRange('A:A');
var posContsDataValues = posContsData.getValues();
for (ii = 1; ii <= posContsData.getNumRows(); ii++) {
iii = ii-1;
posConts[iii] = posContsDataValues[ii][1];
}
I had no problems with using the collection in the values[0][0] format before.
Is this a bug?
Thanks.
You’re confusion the indexes. Both arrays start on 0 (as all arrays in javascript). But you’re using
iiwhich starts on 1 onposContsDataValuesand zero basediiionposConts. You’re also accessing index1on each row, which is wrong, since you get only one columnA:Aand it’s also zero-based.I’m not sure what you’re trying to do, but from your snippet, here is a “fixed” loop.