title: Making table in google apps script from array
body: <pre><code>function arrayMail(){
      var ss=SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheetByName('Sheet1');
      var startRow = 2;
      var lastRow = sheet.getLastRow();
      var lastColumn = sheet.getLastColumn();
      var range = sheet.getRange(startRow,1,lastRow,lastColumn);
      var data = range.getValues();
      var array = [];
      for(var i=0;i&lt;data.length;++i){
          var row = data[i];
          var rowTemp=[]; //create a blank array that will hold only the desired    columns in this row
          for (var j=0; j&lt;row.length; j++)//iterates through columns
          {
             if(j==4||j==3||j==1||j==5){continue;} 
             rowTemp.push(row[j])
  
          }    
          var emailPos = row[3];
          var date = row[2];   
          if(emailPos =='example4@gmail.com'&amp;&amp; date == 0){
              array.push(rowTemp);
          }
      }
      GmailApp.sendEmail('example1@gmail.com','This is a test',array.join('\n\n'));
  }
  </code></pre>
  
  <p>Above script I used for me sending email when date count is 0 and the email become the reference who to email. I wanted to make the array (which is in plain text if using script above) become a table format. I'm stuck with the table formatting. The question is, how do I make it in table format here? <em>Beginner level in scripting</em></p>
  
  <hr>
  
  <p>After reading from book/examples, I came up with below script. But it doesn't work as intended;</p>
  
  <pre><code>   function arrayMail(){
         var ss=SpreadsheetApp.getActiveSpreadsheet();
         var sheet = ss.getSheetByName('Sheet1');
         var startRow = 2;
         var lastRow = sheet.getLastRow();
         var lastColumn = sheet.getLastColumn();
         var range = sheet.getRange(startRow,1,lastRow,lastColumn);
         var data = range.getValues();
         var tableStart = "&lt;table border=\"1\"&gt;&lt;tr&gt;";
         var tableEnd = "&lt;/tr&gt;&lt;/table&gt;";
         var array = [];
         for(var i=0;i&lt;data.length;++i){
             var row = data[i];
             var rowTemp=[]; //create a blank array that will hold only the desired columns in this row
         for (var j=0; j&lt;row.length; j++)//iterates through columns
         {
             if(j==4||j==3||j==1||j==5){continue;} 
             rowTemp.push('&lt;td&gt;'+row[j]+'&lt;/td&gt;');      
         }    
         var emailPos = row[3];
         var date = row[2];   
             if(emailPos =='example4@gmail.com'&amp;&amp; date == 0){
             array.push(rowTemp);
        }
      }
      var HTMLbody = tableStart +array.join('')+tableEnd;
      GmailApp.sendEmail('example@gmail.com','This is a test',HTMLbody,{htmlBody:HTMLbody});
      }
  </code></pre>
  
  <p>Result:  </p>
  
  <p><img src="https://i.stack.imgur.com/xfrEB.png" alt="Image of result"></p>
  
  <p>What I wanted to be is like;  </p>
  
  <p>Infusion Pump 0<br>
  Infusion Pump 0</p>