Check if all array elements are unique

OSCC · JavaScript, Array · Jan 7, 2021

Checks if all elements in an array are unique.

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

Recommended snippets