title: Google apps script : Align strings during display
body: <p>I am looking to update a google form drop down list using concatenation of 3 columns (arrays in reference to the code). The output looks correct but the alignment is still not right even after padding individual strings. Here is my sample code :</p>
  
  <pre><code>function updateForm1(){
  
    var items = [ ["apple", "organic", "101"], ['banana', 'small', '102'], ['pomegranate', 'medium', '1']];
    var itemnames = ['apple' , 'banana', 'pomegranate'];
    var description = ['organic' , 'small', 'medium'];
    var ordercode = ['101', '102', '1'];
    var l1 = itemnames.reduce(function (a, b) { return a.length &gt; b.length ? a : b; }).length;
    var l2 = description.reduce(function (a, b) { return a.length &gt; b.length ? a : b; }).length;
    var l3 = ordercode.reduce(function (a, b) { return a.length &gt; b.length ? a : b; }).length;
  
  
    var dropdownlist = [];
    for (var i =0 ; i &lt; items.length; i++)
    {
      if(items[i][0].length &gt; 0) {
        items[i][0] = items[i][0].padEnd(l1,"*"); 
  
      }
      else 
        items[i][0] = "".padEnd(l1,"*"); 
      if(items[i][1].length &gt; 0) {
        items[i][1] = items[i][1].padEnd(l2,"*");
  
      }
      else 
        items[i][1] = "".padEnd(l2,"*"); 
      if(items[i][2].length &gt; 0) {
        items[i][2] = items[i][2].padEnd(l3,"*");
  
      }
      else 
        items[i][2] = "".padEnd(l3,"*"); 
      dropdownlist[i] = items[i][0] + " | " + items[i][1] + " | " + items[i][2];
      Logger.log(dropdownlist[i]);
  
    }
  
  
  }
  </code></pre>
  
  <p>Log :</p>
  
  <pre><code>[20-06-19 12:12:47:845 IST] apple****** | organic | 101
  [20-06-19 12:12:47:848 IST] banana***** | small** | 102
  [20-06-19 12:12:47:849 IST] pomegranate | medium* | 1**
  </code></pre>
  
  <p>But when I update the form or see the log, values don't seem to be aligned.See pic below. How can I make the dropdown values appear aligned to columns?<a href="https://i.stack.imgur.com/ofeEc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ofeEc.png" alt="enter image description here"></a></p>