GAS – Get Array from Data Validated Range

Been happily grabbing data ranges from cell ranges in google sheets for ages, but never spotted that if you have a range where all the cells have data validation in them (e.g. a list of values or list from range), then even if they are blank, e.g. no selection has been made, GAS still counts them if you get the “length” of the array. This little snippet deals with that!

One thought on “GAS – Get Array from Data Validated Range

  1. Found a couple of other ways – inline

    var myarray = SpreadsheetApp.getActive().getRange(“A1:A10”).getValues().filter(String);

    or

    var myarray = SpreadsheetApp.getActive().getRange(“A1:A10″).getValues().filter(Boolean);

    or possibly both?

    or

    [”,’1′,’2′,3,,’4′,,undefined,,,’5′].join(”).split(”);

    which gives

    [“1″,”2″,”3″,”4″,”5”]

Leave a Reply

Your email address will not be published. Required fields are marked *