DEV Community

cortim
cortim

Posted on

Quick Tip: Find if array has duplicates

Given the array below, which contains duplicates:
const arr = [1, 2, 5, 2, 6, 1];

We can perform the following check:
const hasDuplicates = (new Set(arr)).size !== arr.length;

The result is true, indicating the presence of duplicates in the array.

Top comments (0)