Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to find duplicate values in an array javascript

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 ]
Source by attacomsian.com #
 
PREVIOUS NEXT
Tagged: #find #duplicate #values #array #javascript
ADD COMMENT
Topic
Name
9+9 =