Find duplicate numbers from given Array

Question: Find duplicate numbers from given Array.

Answer:

function find_duplicate_in_array(arra1) {

var i,
len = arra1.length,
result = [],


obj = {};

for (i = 0; i < len; i++) {

if (!obj.hasOwnProperty(arra1[i])) {

obj[arra1[i]] = 1;

}
else {

result.push(arra1[i]);

}

}

result = [...new Set(result)]

return result;

}
var arr = [1, 2, -2, 4, 5, 4, 7, 8, 7, 7, 71, 3, 6];
alert(find_duplicate_in_array(arr));

Try it yourself: