Javascript Set check array duplicates

Description

Javascript Set check array duplicates

function checkDuplicates(arr) {
    var mySet = new Set(arr);
    return mySet.size < arr.length;
}
let a = checkDuplicates([1,2,3,4,5]); // false
console.log(a);/* ww  w .ja v a  2 s.  c  o  m*/

a = checkDuplicates([1,1,2,3,4,5]); // true
console.log(a);



PreviousNext

Related