Find and remove duplicate values of array list in Google Apps Script - codylab

 How to remove duplicates values of an array list using Google apps script?

Removing  duplicates values of arrays  |  Getting Unique_List of arrays in AppsScript

Dear partner, as by title of this article we are going to set a function to remove duplicate value of arrays. Look at the following Google sheet column A. 
What did you observe? Column A has a list of  animals' names. Some animals' names have been typed more that once. I want to remove the repeated animals names in html output. In this condition we have to use following code snippet. 

function iremove(){
var sv = ws.getDataRange().getValues();
var x='';
//looping all values
for(var i =0;i<sv.length;i++){
x+=sv[i][0]+",";}
//getting sheet values as array 
//sorting and seprating all value by comma
var cv = x.split(",").sort();
var rd = new Set(cv);
rd.forEach(uv=>{
//after removing of duplicates value
Logger.log(uv);
});
//before removing of duplicates values
Logger.log(cv);
  }
Full souce code for html output:
Code.gs
function doGet(e) {
  return HtmlService.createTemplateFromFile('index').evaluate();
  }

var ws = SpreadsheetApp.openById("sheet id").getSheetByName("animals");

   function iremove(){
var sv = ws.getDataRange().getValues();
var x='';
//looping all values
for(var i =0;i<sv.length;i++){
x+=sv[i][0]+",";}
//getting sheet values as array 
//sorting and seprating all value by comma
var out='<ul>'
var cv = x.split(",").sort();
//before removing of duplicates values
out+='Before:<li>'+cv+'</li>';
var rd = new Set(cv);
rd.forEach(uv=>{
//after removing of duplicates value
out+='<li>'+uv+'</li>';
});
return out+'</ul>';
  }
index.html
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body onload="ifetch()">
<div id="info"></div>
    <script>
       function ifetch() {
     var info = document.getElementById('info');
     function fail(error){
     info.innerHTML = "<span style='color:red'>"+error+"</span>";
     };
     function pass(res){
     info.innerHTML =res;
     };
     info.innerHTML = "Working on...";
     google.script.run.withFailureHandler(fail)
                      .withSuccessHandler(pass)
                      .iremove();};

      </script>
  </body>
</html>
>>>TRY TO CHECK OUT , IF ANY ERROR FOUND. PLEASE LET ME KNOW BY COMMENT.
I'LL TRY MY LEVEL BEST TO FIX THE PROBLEM. THANKS FOR VISITING CODYLAB Have a nice day! 
-------------------------- -------------------------  

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.