Skip to content

Instantly share code, notes, and snippets.

@devudit
Created July 15, 2016 12:22
Show Gist options
  • Select an option

  • Save devudit/5c4598c52777aaff3f394d6690a9dcb1 to your computer and use it in GitHub Desktop.

Select an option

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
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