If we have an array (even not ordered) and we want to remove duplicated values, we can use the filter method:

let duplArray = ["A","B","AA","C","B","C","AC","AA","D","E","G","E","F","A"]; let uniqueArray = duplArray.filter(function (item, pos)
{ return duplArray.indexOf(item) == pos;
});
console.log(JSON.stringify(duplArray));
// expected ["A","B","AA","C","B","C","AC","AA","D","E","G","E","F","A"] console.log(JSON.stringify(uniqueArray));
// expected ["A","B","AA","C","AC","D","E","F","G"]

Laisser un commentaire