remove all duplicates from an Array
const removeDuplicates = arr => [...new Set(arr)];
Source: dev.to
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) // [ 1, 21, 34, 12 ]
remove duplicates array.filter
// removeDuplicates ES6 const uniqueArray = oldArray.filter((item, index, self) => self.indexOf(item) === index);
Remove duplicate items in an array
let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd'] let myOrderedArray = myArray.reduce(function (accumulator, currentValue) { if (accumulator.indexOf(currentValue) === -1) { accumulator.push(currentValue) } return accumulator }, []) console.log(myOrderedArray)
Source: developer.mozilla.org