I’m creating a small script for Google Spreadsheets that will move numbers into one column and strings into the other. Should be pretty basic, but I’m just barely playing around with JS and naturally I’ve come across something that doesn’t make sense to me whatsoever.
Here’s the code.
function moveData() {
var sheet = SpreadsheetApp.getActiveSheet();
var dataToMove = sheet.getRange("A1:A5003");
var lastRow = sheet.getLastRow();
for (var i = 0; i <= lastRow - 1; i++)
{
var unparsedValue = dataToMove[i];
if(unparsedValue != "" && typeof unparsedValue === "number" && !isNaN(unparsedValue))
{
var parsedValue = unparsedValue;
Logger.log(parsedValue);
}
}
}
It’s not all done obviously, but throws an error at var unparsedValue = dataToMove[i];
Error is as follows: Class “$Proxy810” has no public instance field or method named “0”
what is $Proxy810, and if I understand correctly why would it have a field, or method named “0”??
Little frustrating and any insight into this would be appreciated.
It is obvious that
sheet.getRange("A1:A5003")returns$Proxy810instance and as first value in your loop is0your code on this lineand
$Proxy810doesn’t have property like that.I suppose that you need not loop using brackets, but use some method instead, although I’m not familiar with Spreadsheets API, but you need to look for something like
dataToMove.getRow(i)EDITED: As first script example on google show, you need to use this code:
So in your case you need to alter your code as follows: