Possible Duplicate:
Easiest way to find duplicate values in a JavaScript array
Let’s say I have an array with thousands of elements and
I want to return true if there are 2 or more elements with the same value.
I know I can run a for loop and do a check on every pair of elements to find the answer.
But is there a faster way? And what’s the best way?
This is basically the Element Distinctness Problem. You can read about it, but with only 1000 elements, the optimizations are probably not worth it.
If you really want to optimize it, you can push the elements into a hash table and check if collisions are duplicates. This will give you O(n) on average (amortized), but O(n^2) in worst case.