Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Unique Char</title>
</head>
<body>
<textarea rows="5" id="str">V2EX是一个知名技术创意网站,由设计师、程序员及有创意的人参与的社区。它基于兴趣将用户创建的内容组织分类成不同“节点”,网站以内容的活跃程度决定在首页排序的位置。</textarea>
<br>
<button id="btn">Get Unique Char</button>
<br>
<textarea rows="5" id="res"></textarea>
</body>
</html>
 
String.prototype.getUnique = function(){
   var u = {}, a = [], arr=this.split('');
   for(var i = 0, l = arr.length; i < l; ++i){
      if(u.hasOwnProperty(arr[i])) {
         continue;
      }
      a.push(arr[i]);
      u[arr[i]] = 1;
   }
   return a.join('');
}
document.getElementById('btn').onclick = getUniqueChar;
function getUniqueChar() {
  document.getElementById('res').value = document.getElementById('str').value.getUnique();
}
setTimeout(getUniqueChar, 0);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers