📜  javascript 从数组中删除唯一性 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:09.088000             🧑  作者: Mango

代码示例2
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] )); //[]