I have an object that I want to access it’s members by using a list of “headers” in an array that match the object’s member names. I pull the values of the “headers” from a spreadsheet into an array (see log output at bottom). Then, when I iterate over the array using a for loop, I can’t seem to access the Object’s members. Why doesn’t this work?
var e = new Object();
e.parameter = new Object();
e.parameter.identifier = "test";
//...
Logger.log(Utilities.jsonStringify(e));
var ss = SpreadsheetApp.getActiveSpreadsheet();
var renters = ss.getSheetByName("Renters");
var headers = ObjApp.camelArray(renters.getRange(1,1,1,renters.getLastColumn()).getValues()[0]);
Logger.log(headers);
var data = [];
for(var h=0;h<headers.length;h++)
{
Logger.log(headers[h]);
data.push(e.parameter[headers[h]]);
};
Logger.log(data);
LOG OUTPUT:
{"parameter":{"indentifier":"test"}}
[identifier, address, tenants, gracePeriodDays, gracePeriodRecurrence, lateFeeAmount, startingBalance, startingDate, rentAmount, dayOfMonthDue]
identifier
address
tenants
gracePeriodDays
gracePeriodRecurrence
lateFeeAmount
startingBalance
startingDate
rentAmount
dayOfMonthDue
[null, null, null, null, null, null, null, null, null, null]
It seems to work in my second example when I don’t pull the string value from an array over an iteration.
function test(e){
var o = new Object();
o.test1 = new Object();
o.test1.test2 = 0;
var test3 = "test2";
Logger.log(o.test1[test3]);
Logger.log(Utilities.jsonStringify(o));
};
LOG OUTPUT:
0.0
{"test1":{"test2":0}}