title: Remove duplicates values in array Google Apps Script
body: <p>I would like to know how to remove duplicates values from 2 arrays, combined into one main array.</p>
  
  <p>This values must NOT be removed from the sheets or document, just in the array, thats why I didnt use clear() or clearContents() built in functions;</p>
  
  <p>Ive also tried to modify the <a href="https://developers.google.com/apps-script/articles/removing_duplicates" rel="nofollow">removeDuplicates()</a> function from the GAS tutorials, but it throws me rows inside columns from A to Z, instead filtered rows...a total mess.</p>
  
  <p><strong>Notes:</strong></p>
  
  <p>Parameters from <strong>getClients()</strong> are from others functions, and works ok.</p>
  
  <p><strong>newClients</strong> list clients from the sheet 'Users' and <strong>newUsers</strong> list users from another sheet called 'Data'.</p>
  
  <p>Boths sheets belongs to the same spreadsheet.</p>
  
  <p><strong>newClients and newUsers</strong>: both arrays only contains strings (usernames), and in both there are duplicated values.</p>
  
  <p>So the goal is identified and remove those values, the original and the duplicate.</p>
  
  <p>Should be easier I think, but Im new in JS, so everything Ive been tried, didnt worked.</p>
  
  <p>Thanks</p>
  
  <p><strong>The Code</strong></p>
  
  <pre><code>function getAllClientsFromData(body,project){
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
  
    // Active the Sheets
    var sheet= ss.getSheets()[1,3];
  
    // Access data in Sheet "Data"
    var rangeC = ss.getRangeByName("clients"); //A:2:C273  
    var rangeU = ss.getRangeByName("names"); //A5:A
  
    var clients = rangeC.getValues();
    var users   = rangeU.getValues();
  
    var lastRow = sheet.getLastRow()-2;
  
    body += "&lt;h2&gt;Total of " + lastRow + " clients in " + project + "&lt;/h2&gt;" 
    body += "&lt;table style=" + STYLE.TABLE + "&gt;";
    body += getClients(ss,clients,users,project);
    body += "&lt;/table&gt;";
  
    return body;  
  
  }
  
  function getClients(ss,clients,users,project){
  
    var body = "";
  
    var newClients = [];
  
    for( var g = 0; g &lt; clients.length; g++ ){
  
      var currentProject = clients[g][2];
  
      if( clients[g]!= "" ){
  
         newClients.push(clients[g][0]);
  
      } 
  
    } // end for
  
    var newUsers = []; 
  
    for( var u = 0; u &lt; users.length; u++ ){
  
      if( users[u] != "" ){    
  
        newUsers.push(users[u][0]);
  
      }
  
    } // end for
  
    var allData = newUsers.concat(newClients);
  
    var uniqueData = allData.sort();
  
    body += "&lt;tr&gt;&lt;td style=" + STYLE.TD + "&gt;" + uniqueData.join("&lt;/td&gt;&lt;tr&gt;&lt;td style=" + STYLE.TD + "&gt;") + "&lt;/td&gt;&lt;/tr&gt;&lt;/tr&gt;";
  
    return body;
  
  }
  </code></pre>
  
  <p><strong>UPDATES!</strong></p>
  
  <p>The answers works great filtering, but Im getting the same result as on my previous tries: displaying the filtered results. I need to remove them from the array. example:</p>
  
  <pre><code>var array = ['aa','bb','aa','ff','pp', 'pp'];
  filtering code...
  var array = ['bb','ff'];
  </code></pre>
  
  <p>I try to add splice() js method but the params I pass, does not working ok.</p>