remove duplicate from array code example
Example 1: js delete duplicates from array
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let unique = [...new Set(names)];
console.log(unique);
Example 2: use set to remove duplicates in javascript
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let unique = [...new Set(names)];
console.log(unique);
Example 3: javascript remove duplicates from array
const initialArray = ['a', 'a', 'b',]
finalArray = Array.from(new Set(initialArray));
Example 4: javascript to remove duplicates from an array
uniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})
Example 5: javascript filter array remove duplicates
arrayWithOnlyUniques = [...new Set(arrayWithDuplicates)]
Example 6: 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)