I need to find the number of unique elements in an array.
var myArray = [ 10, 10, 20, 20, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 60 ];
I want count = 6 (the number of unique elements in the array)
And is there a way to do this without iterating through an array? (I guess this would be the fastest way?).
ANSWER: I used the .filter method as shown below. My actual array element is much more complicated. I finished the iteration through my array and created a new array. Each element of the new array was a .substr of the old element. Then the .filter method below worked fine. THANKS to everyone!
source share