Check if array has duplicates

OSCC · JavaScript, Array · Oct 22, 2020

Checks if there are duplicate values in a flat array.

const hasDuplicates = arr => new Set(arr).size !== arr.length;
hasDuplicates([0, 1, 1, 2]); // true
hasDuplicates([0, 1, 2, 3]); // false

Recommended snippets