Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)));
@pankajkrr
Copy link

pankajkrr commented Jul 27, 2019

Find brief article here : Click here to view

@fosteev
Copy link

fosteev commented Mar 10, 2020

const uniq = elements.reduce((acc, value) => acc.some(i => i.id === value.id) ? acc : acc.concat(value), []); // id your uniq key

@ioness
Copy link

ioness commented Apr 27, 2020

Excelent, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment