Skip to content

Instantly share code, notes, and snippets.

@Shariar-Hasan
Created January 20, 2021 18:15
Show Gist options
  • Save Shariar-Hasan/18e5281930260965f3ded5fa1bab6f43 to your computer and use it in GitHub Desktop.
Save Shariar-Hasan/18e5281930260965f3ded5fa1bab6f43 to your computer and use it in GitHub Desktop.
To remove duplicate items from an array in javascript
var numbers = [1,2,5,3,7,5,6,8,9,9,0,3,4,5,6,5,5,4,3,3,4,4];
function duplicateRemover(numbers)
{
var uniqueArray = []
for(var i = 0; i< numbers.length ; i++)
{
if(uniqueArray.indexOf(numbers[i]) == -1)
{
uniqueArray.push(numbers[i]);
}
}
return uniqueArray;
}
console.log(duplicateRemover(numbers));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment