Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript remove uniques from array

function getNotUnique(array) {
    var map = new Map();
    array.forEach(a => map.set(a, (map.get(a) || 0) + 1));
    return array.filter(a => map.get(a) > 1);
}

console.log(getNotUnique([1, 2, 2, 4, 4])); //[2, 2, 4, 4]
console.log(getNotUnique([1, 2, 3] )); //[]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #remove #uniques #array
ADD COMMENT
Topic
Name
9+3 =