OneBite.Dev - Coding blog in a bite size

Check array only contains unique value javascript

How to verify array is only contains unique value in Javascript. Answer is using Set!

You can check if an array contains only unique values in JavaScript by using a Set, which inherently only allows unique values.

Here’s how:

function isUnique(arr) {
    return new Set(arr).size === arr.length;
}

For example, calling isUnique([1, 2, 3, 4, 5]) will return true, but calling isUnique([1, 2, 3, 3, 5]) will return false.

How to check if string is... →
javascript