'Script will not run without a console.log entry?

let me start by saying I'm very new to coding:

I am trying to understand why if I remove this line console.log(m+" Why Must I Run") then the VL.getRangeByIndexes(0, 13+s, arrayLIST.length, arrayLIST[0].length).setValues(arrayLIST); states the rows/columns do not match, but if I leave the console.log(m+" Why Must I Run") in then the script works fine with no errors.

Script below:

function main(workbook: ExcelScript.Workbook) {
  let VL = workbook.getWorksheet("VL");
  let usedRange = VL.getUsedRange();
  let lastRow = usedRange.getRowCount();
  let arrayData = new Array([]);
  arrayData = VL.getRange("A2:C" + lastRow).getValues();
  let arrayLIST = new Array([]);
  let arrSite = new Array([]);
  let LR = LRcol("D1:D");
  arrSite = VL.getRange("D2:D" + LR).getValues();
  let s = 0
  for (let m = 0; m < arrSite.length; m++) {
    console.log(m + " Why Must I Run")
    arrayLIST.splice(0, arrayLIST.length);
    for (let i = 0; i < arrayData.length; i++) {
      if (arrayData[i][1].toString() === arrSite[m].toString() && arrayData[i][2] == 1) {
        arrayLIST.push([arrayData[i][0], arrayData[i][1]]);
      } else {
      }
    }
    s = s + 2;
    VL.getRangeByIndexes(0, 13 + s, arrayLIST.length, arrayLIST[0].length).setValues(arrayLIST);
  }
  function LRcol(ColString: string) {
    let LRCol = new Array([])
    let Count = 0
    LRCol = VL.getRange(ColString + lastRow).getValues();
    for (let x = 0; x < LRCol.length; x++) {
      if (LRCol[x][0] != "") {
        Count = Count + 1
      }
    }
    // console.log(Count)
    return Count
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source