programming-examples/js/Array/Write a JavaScript program to find duplicate values in a JavaScript array..js
2019-11-15 12:59:38 +01:00

16 lines
354 B
JavaScript

function find_duplicate_in_array(arra1) {
var i,
len=arra1.length,
result = [],
obj = {};
for (i=0; i<len; i++)
{
obj[arra1[i]]=0;
}
for (i in obj) {
result.push(i);
}
return result;
}
var arr = [1, 2, -2, 4, 5, 4, 7, 8, 7, 7, 71, 3, 6];
console.log(find_duplicate_in_array(arr));