how to clear duplicates in an array code example
Example 1: remove duplicates from array
let chars = ['A', 'B', 'A', 'C', 'B'];
let uniqueChars = [...new Set(chars)];
console.log(uniqueChars);
output:
[ 'A', 'B', 'C' ]
Example 2: remove duplicates array.filter
// removeDuplicates ES6
const uniqueArray = oldArray.filter((item, index, self) => self.indexOf(item) === index);