title: Passing variables between functions by reference in Google Apps Script
body: <p>I'm really new to Google Apps Script and just started a few days ago to learn it. I have previous knowledge in C++ but not more.</p>
  
  <p>I tried to write my first script doing some action on a google sheet. Here is the code I created so far:</p>
  
  <pre><code>var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getActiveSheet();
  
  function MainFunc() {
    var LoopCounter = 0;
    SaveDataInArray(LoopCounter);
    Logger.log(LoopCounter);
  }
  
  function SaveDataInArray(LoopCounter) {
    var InfiniteForLoopTrigger = 1;
    var range;
    var VolumeArray = [];
    var SignalArray = [];
  
    //Save Data in Array
    for(var i = 2; InfiniteForLoopTrigger &gt; 0; i++){
      range = s.getRange(i, 1);
      if(range.isBlank()){
        break;
      }
      VolumeArray[LoopCounter] = s.getRange(i, 1).getValue();
      SignalArray[LoopCounter] = s.getRange(i, 2).getValue();
      LoopCounter++;
    }
  }
  </code></pre>
  
  <p>I realized that the value of LoopCounter is not changed, after being passed to the function SaveDataInArray. I know that having an ampersand (&amp;) in front of the argument, like</p>
  
  <pre><code>function SaveDataInArray(&amp; LoopCounter)
  </code></pre>
  
  <p>helps the problem in C++, but I don't know how to get along with it in Google Apps Script. </p>
  
  <p>Would love if someone could help me on that.
  Thanks and best regards,
  Max</p>