I am trying to take a column of names and put them into an array.
function printDriver() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var driverArray = [];
driverArray = sheet.getRange("H2:H34").getValues();
driverArray.join('').split('');
I am unsure if this is the correct way to do it. Names only appear in H2:H34
of sheet 0 in my spreadsheet. I want to get all those values, put them into an array and delete empty values but I believe that I end up with an empty array.
You just need to flat the array and then filter out the empty cells.
You can do that with one line of code:
driverArray = sheet.getRange("H2:H34").getValues().flat().filter(r=>r!="");
function printDriver() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var driverArray = sheet.getRange("H2:H34").getValues().flat().filter(r=>r!="");
}
driverArray
is the desired array.
What does the range method getValues() return and setValues() accept?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With