DEV Community

Discussion on: JavaScript: How to Check if an Array has Duplicate Values

Collapse
 
johandalabacka profile image
Johan Dahl • Edited

or use almost the same technique as the author:

function checkForDuplicates(array, keyName) {
  return new Set(array.map(item => item[keyName])).size !== array.length
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
igorfilippov3 profile image
Ihor Filippov

Yep. It is cleaner than mine.