I'm trying to find the last column in a range, but the problem is I can't specify the script to only check within an array instead of the entire sheet. I was able to use this bit of code to find the last row but I'm having trouble understanding how this can be changed to find the column instead of row.
function findLastRow() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet1');
const data = sh.getRange("A:K").getValues();
const mR = sh.getMaxRows();
const indexes = [];
data[0].forEach((_,ci)=>{
let col = data.map(d => d[ci]);
let first_index = col.reverse().findIndex(r=>r!='');
if(first_index!=-1){
let max_row = mR - first_index;
indexes.push(max_row);
}
});
last_row = indexes.length > 0 ? Math.max(...indexes) : 0;
console.log(last_row);
}
Can anyone explain to me how this function could be changed up a bit to search for the column instead of the row?