Skip to content

Instantly share code, notes, and snippets.

@houoop
Created March 21, 2013 05:33
Show Gist options
  • Save houoop/5210887 to your computer and use it in GitHub Desktop.
Save houoop/5210887 to your computer and use it in GitHub Desktop.
JS数组去重
Array.prototype.dedupe=function () {
var hash={},result=[],
hasown=Object.prototype.hasOwnProperty;
for (var i = this.length - 1; i >= 0; i--) {
if(!hasown.call(hash,this[i])){
hash[this[i]]=1;
result.push(this[i]);
}
};
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment