title: Google Sheets - generating all possible combinations of strings from columns
body: <p>Hi (and sorry for ambiguous question Title, welcome to better ones)</p>
  
  <p>I currently have a table of data looking like this:</p>
  
  <pre><code>CLASS       Type A  Type B  Type C
  A              1       3      7
  B              2       4      8
  C                               
  D               
  </code></pre>
  
  <p>Either through formulas (I don't see how) or a script, I am trying to get the combination of each 'Class' with each type, for example:</p>
  
  <p>A1, A2, A3, A4, A7, A7 and A13 A14 A17 etc and A137 A138 etc (+ all other possibilities). So far I only managed to get the '2 digits' version. </p>
  
  <p>Code so far below (in my data I have some extra columns which tell me what types I need for that specific class):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function expand(){
    //create the sheet to use
    var ss = SpreadsheetApp.getActive().getSheetByName('data');
    //create blank array
    var fin_resultAry = [];
    //extract the range of data
    var main_Range =  ss.getRange('A2:D5').getValues();
    //extract all the variations of data
    var range1 = ss.getRange('E2:E3').getValues();
    var range2 = ss.getRange('F2:F3').getValues();
    var range3 = ss.getRange('G2:G3').getValues();
    
    //create dictionary with variations
    var var_dict = {1: range1, 2: range2, 3: range3}
      
    //main for loop
    for(var k = 0; k&lt;main_Range.length;k++){
      //push the initial no type variation
      fin_resultAry.push(main_Range[k][0]);    
      //create the loop to check what class variations have the set value == true
      for(var i = 1; i&lt;=main_Range[k].length;i++){
        if (main_Range[k][i] == true){
          //for each of the variations add the var string to the initial class and push it
          for(var j = 0; j&lt;var_dict[i].length;j++){
            fin_resultAry.push(main_Range[k][0] + " " + var_dict[i][j][0]);
          }  
        }
      }
    }    
    return fin_resultAry;
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Also note that my data has a lot of 'Classes' and more than 3 types which makes using formulas impossible as they are limited to X number of rows/characters/etc.</p>