function convertToEnts(formObject){
var sheet = SpreadsheetApp.getActiveSheet();
var columns = sheet.getRange(1,1,1, sheet.getLastColumn()).getValues()[0];
var columnValues = String(columns).split(","); //this is something I tried on the advise of https://stackoverflow.com/questions/17044825/indexof-returning-1-despite-object-being-in-the-array-javascript-in-google-sp
var data = sheet.getRange(2, 1,sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
for (var i=0;data.length;i++){
row = data[i];
var entity = {}
//formObject: {identity=lat,...,other form attributes here}
for (var key in formObject){
Logger.log(formObject[key]);
Logger.log(typeof formObject[key]);
Logger.log(columnValues);
var indexOfKey = columnValues.indexOf(formObject[key]);
Logger.log(indexOfKey);
var value = formObject[key]; //row[indexOfTimestamp]
entity[key] = row[indexOfKey];
}
}
}
Logs:
[17-06-15 15:48:02:071 PDT] lat
[17-06-15 15:48:02:072 PDT] string
[17-06-15 15:48:02:072 PDT] [a, b, c, lat]
[17-06-15 15:48:02:073 PDT] -1.0
So the formObject[key] or value is lat. The type is a string (all good so far). The column looks like [a,b,c,lat]. And I basically want to return the index of lat which should be 3 I think. Im struggling with that indexOfKey variable. Anything I try returns a -1 as if the string is not in the array. Any suggestions?