This is the code I found as an answer to this question: Write a JavaScript program to remove duplicate items from an array (ignore case sensitivity).
var arr1=[3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3, 'A'];
var uniqueArray = arr1.filter(function(elem,i,rep){
return i == rep.indexOf(elem);
})
console.log(uniqueArray);
I know what filter() does and that indexOf is used to find the index of the first occurence of an element, but I don't understand how this line:
i == rep.indexOf(elem);
introduces only the unique elements to uniqueArray.
var uniqueArray = [...new Set(arr1)];
– Rabiah