I want to loop through all sheets (I was 57) and get all the elements from the first column,and add them into an array to then, that I can later access with ALL the ids from ALL the sheets.The problem with my code is that the ids array is not loading correctly. When I print ids.length it equals 0. So I'm guessing something is wrong on my forEach loop where it won't push the values into the array.
function countLinesPerCharacter() {
let app = SpreadsheetApp;
let spreadsheet = SpreadsheetApp.getActive()
let allSheets = spreadsheet.getSheets()
let targetSheet = app.getActiveSpreadsheet().getSheetByName("lines");
let ids = []
let y = 2
//goes thrrough each sheet
allSheets.forEach(function(sheet){
sheet.activate()
//goes through the rows
//row col
let lastRowNumber = spreadsheet.getLastRow();
for(let i = 0; i < lastRowNumber.length; i++) {
let questionID = spreadsheet.getRange(i, 1).getValue();
ids.push(questionID) // IT WON'T LOAD THE questionID into ids ----
y++
}
})
targetSheet.getRange(1, 5).setValue(ids.length); //ids.length = 0
targetSheet.getRange(1, 1).setValue("Done going through each sheet");
}