Skip to content

Instantly share code, notes, and snippets.

@libo1106
Created November 12, 2013 09:02
Show Gist options
  • Save libo1106/7427779 to your computer and use it in GitHub Desktop.
Save libo1106/7427779 to your computer and use it in GitHub Desktop.
JavaScript数组简单去重
Array.prototype.unique = function(){
var results=this.sort();/*排序*/
for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[ i - 1 ] ) {
results.splice( i--, 1 );/*删除相邻相同元素*/
}
}
return results;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment