Skip to content

Instantly share code, notes, and snippets.

@monjer
Created February 27, 2018 13:39
Show Gist options
  • Select an option

  • Save monjer/499dc1f4fe5f30dba0f8a762c6956eeb to your computer and use it in GitHub Desktop.

Select an option

Save monjer/499dc1f4fe5f30dba0f8a762c6956eeb to your computer and use it in GitHub Desktop.
JS remove duplicate element in array
function removeDup(arr){
return [...new Set(arr)];
}
function removeDup(arr){
return Array.from(new Set(arr));
}
function removeDup(arr){
let array = [];
arr.forEach(function(item){
if(array.indexOf(item) === -1){
array.push(item);
}
});
return array;
}
function removeDup(arr){
let array = [];
arr.forEach(function(item){
if(array.indexOf(item) === -1){
array.push(item);
}
});
return array;
}
function removeDup(arr){
var res = arr.filter(function(item, index, array){
return arr.indexOf(item) === index;
})
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment