fastest way to detect if duplicate entry exists in javascript array?
arrays, javascript
Solution
If you sort the array, the duplicates are next to each other so that they are easy to find:
arr.sort();
var last = arr[0];
for (var i=1; i<arr.length; i++) {
if (arr[i] == last) alert('Duplicate : '+last);
last = arr[i];
}
Problem
``` var arr = ['test0','test2','test0']; ``` Like the above,there are two identical entries with value "test0",how to check it most efficiently?