Answers for "javascript check if array has duplicates"

1

javascript check if array has duplicates

function hasDuplicates(array) {
    return (new Set(array)).size !== array.length;
}
Posted by: Guest on July-28-2020
1

check for duplicates in array javascript

[1, 2, 3].every((e, i, a) => a.indexOf(e) === i) // true

[1, 2, 1].every((e, i, a) => a.indexOf(e) === i) // false
Posted by: Guest on January-01-2021
0

how to count duplicates in an array javascript

arr.reduce((b,c)=>((b[b.findIndex(d=>d.el===c)]||b[b.push({el:c,count:0})-1]).count++,b),[]);
Posted by: Guest on December-16-2020
0

Find duplicate or repeat elements in js array

const a = [4,3,6,3,4,3]

function count_duplicate(a){
 let counts = {}

 for(let i =0; i < a.length; i++){ 
     if (counts[a[i]]){
     counts[a[i]] += 1
     } else {
     counts[a[i]] = 1
     }
    }  
    for (let prop in counts){
        if (counts[prop] >= 2){
            console.log(prop + " counted: " + counts[prop] + " times.")
        }
    }
  console.log(counts)
}

count_duplicate(a)
Posted by: Guest on October-11-2021

Code answers related to "javascript check if array has duplicates"

Code answers related to "Javascript"

Browse Popular Code Answers by Language