Created
November 12, 2013 09:02
-
-
Save libo1106/7427779 to your computer and use it in GitHub Desktop.
JavaScript数组简单去重
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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