title: Google Apps Script - ForEach in Range
body: <p>For each row in a range, I'd like to add one or several entries to an array, depending on the value of an int, in one of the row's column.
  E.g if my row is :</p>
  
  <pre><code>Val1   1
  </code></pre>
  
  <p>I want to push an object {Val1,'US'} to my array.
  On the other hand, if my row is :</p>
  
  <pre><code>Val1   2
  </code></pre>
  
  <p>I want to push two objects : {Val1,'FR'}, {Val1,'DE'} to my array.
  I can't figure out why the following code doesn't work :</p>
  
  <pre><code>  var range = sheet.getRange("A2:B");
    var results = range.getDisplayValues();
    var array = [];
  
    results.forEach(function(row){          
  
      switch(row[1]){
        case '1' :               
          row[1] = "US";        
          array.push(row);                        
          break;
        case '2' :
          row[1] = "FR";
          array.push(row);      
          row[1] = "DE";
          array.push(row);     
          break; 
        case '3' :
          var entry1 = row;
          var entry2 = row;
          entry1[1] = "UK";
          entry2[1] = "SW";
          array.push(entry1);      
          array.push(entry2);      
          break;            
      }           
    });    
  return array;
  </code></pre>
  
  <p>This returns me twice "DE" and twice "SW". I tried a different way in case three, to make sure that the problem was not with variable reference, but the same thing occurs. Could it be because of the way I'm looping on values ? Why is it behaving this way ?</p>
  
  <p>Thank you for your help. </p>