I am working with the following function in Google Scripts
function writeToSheet(sheet, data, dataName, dataPts) {
var rows = [];
Logger.log(dataPts);
for (var z = 0; z < data.length; z++) {
var subRow = [];
for (var q = 0; q < dataPts.length; q++) {
subRow.push(dataName[z][dataPts[q]])
}
rows.push(subRow);
subRow = [];
}
Logger.log(rows);
dataRange = sheet.getRange(sheet.getLastRow()+1, 1, rows.length, rows[0].length);
dataRange.setValues(rows);
}
I pass the function a sheet to write to, the data which is an array of objects, the dataName which I'm using to try and extract data from the original array and dataPts which is an array of the property names that I'd like to extract from each object in the original array and nest as an array in the finished array - rows.
No matter how I try to make this work, I end up with an array build of the strings which if hardcoded into the function, would give me exactly what I want. However I can't work out how to do this dynamically so that it will work for any data I give it.
Does anyone have any ideas? I thought about trying to filter out properties from each object in the original array and then somehow turn the values from remaining keys into an array for each one, but I have no idea how to do this or if it is possible.
Appreciate any advice anyone might have :)
ifstatements, and that seems fundamental to your objective.