while push to array remove duplicates javascript code example
Example 1: javascript remove duplicates from array
var myArr = [1, 2, 2, 2, 3];
var mySet = new Set(myArr);
myArr = [...mySet];
console.log(myArr);
// 1, 2, 3
Example 2: javascript to remove duplicates from an array
uniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})