how to remove duplicates in an array code example
Example 1: removing duplicates in array javascript
let arr = [1,2,3,1,1,1,4,5]
let filtered = arr.filter((item,index) => arr.indexOf(item) === index)
console.log(filtered)
Example 2: how to remove duplicates in array in javascript
const numbers = [1 , 21, 21, 34 ,12 ,34 ,12];
const removeRepeatNumbers = array => [... new Set(array)]
removeRepeatNumbers(numbers)
Example 3: remove duplicates array.filter
const uniqueArray = oldArray.filter((item, index, self) => self.indexOf(item) === index);
Example 4: remove duplicates in array
uniq = [...new Set(array)];
or
uniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})