Skip to content

Instantly share code, notes, and snippets.

@ravivit9
Forked from telekosmos/uniq.js
Created July 3, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravivit9/adf18a2a9692cccd8b00e4d532c19ae2 to your computer and use it in GitHub Desktop.
Save ravivit9/adf18a2a9692cccd8b00e4d532c19ae2 to your computer and use it in GitHub Desktop.
Remove duplicates from js array (ES5/ES6)
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
var uniqEs6 = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
});
}
var test = ['mike','james','james','alex'];
var testBis = ['alex', 'yuri', 'jabari'];
console.log(uniqueArray(test.concat(testBis)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment