Remove duplicate characters from string

前端 未结 28 907
猫巷女王i
猫巷女王i 2020-12-01 13:09

I have to make a function in JavaScript that removes all duplicated letters in a string. So far I\'ve been able to do this: If I have the word \"anaconda\" it shows me as a

28条回答
  •  暖寄归人
    2020-12-01 13:57

      //One simple way to remove redundecy of Char in String
           var char = "aaavsvvssff"; //Input string
           var rst=char.charAt(0);
           for(var i=1;i=0 ?0:(rst +=  char.charAt(i) ); 
           }
           console.log(JSON.stringify(rst)); //output string : avsf
    

提交回复
热议问题