Skip to content

Instantly share code, notes, and snippets.

@yangg
Created October 6, 2011 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangg/1266760 to your computer and use it in GitHub Desktop.
Save yangg/1266760 to your computer and use it in GitHub Desktop.
js正则匹配数组中不重复的元素
var arr=["a","b","c","a","ba","bc"];
alert(arr.join(",").match( /([^,]+)(?!.*,\1(,|$))/ig));
Array.prototype.deleteEle=function(){
var arr=this,o={},newArr=[],i;
for( i=0;i<arr.length;i++){
if(typeof(o[arr[i]])==="undefined"){
newArr[newArr.length]=arr[i]
}
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment