const numbers = [1, 2, 3, 2, 4, 5, 5, 6];
const set = new Set(numbers);
const duplicates = numbers.filter(item => {
if (set.has(item)) {
set.delete(item);
} else {
return item;
}
});
console.log(duplicates);
// [ 2, 5 ]