This seems like it should be very straight forward, but doesn't seem to be. Something like sheet.getRange(B2:2).getValues().filter(notBlank)
but what do I put in place of notBlank
?
In your situation, how about the following modification?
const res1 = sheet.getRange("B2:2").getDisplayValues()[0].filter(String).length;
console.log(res1)
// or
const res2 = sheet.getRange(2, 2, 1, sheet.getLastColumn() - 1).getDisplayValues()[0].filter(String).length;
console.log(res2)
getDisplayValues
and getValues
can be used.