Find Duplicate Numbers in array using javascript

by Vinoth 2010-02-01 11:30:18


function find_duplicates(arr) {
var len=arr.length,
out=[],
counts={};

for (var i=0;i<len;i++) {
var item = arr[i];
var count = counts[item];
counts[item] = counts[item] >= 1 ? counts[item] + 1 : 1;
}

for (var item in counts) {
if(counts[item] > 1)
out.push(item);
}

return out;
}

Tagged in:

1321
like
0
dislike
0
mail
flag

You must LOGIN to add comments