Created
July 15, 2016 12:22
-
-
Save devudit/5c4598c52777aaff3f394d6690a9dcb1 to your computer and use it in GitHub Desktop.
Remove duplicate element from array in javascript Or remove duplicate element after concat in 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 a = this.concat(); | |
| for(var i=0; i<a.length; ++i) { | |
| for(var j=i+1; j<a.length; ++j) { | |
| if(a[i] === a[j]) | |
| a.splice(j--, 1); | |
| } | |
| } | |
| return a; | |
| }; | |
| /***************************************** | |
| * var x=['1','2','3','3','4','5','5','0','5']; | |
| * x.unique(); | |
| * This will return a array like ["1", "2", "3", "4", "5", "0"] | |
| ***************************************** / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment