The value to validate.
true if the array contains no duplicate entries, otherwise false.
This function checks for duplicate entries using JavaScript Set
semantics (SameValueZero equality).
This means:
NaN is considered equal to NaNUnique primitive values:
isUniqueArray([1, 2, 3]); // true
Duplicate primitive values:
isUniqueArray([1, 2, 1]); // false
Object references:
const a = {};
const b = {};
isUniqueArray([a, b]); // true
isUniqueArray([a, a]); // false
NaN handling:
isUniqueArray([NaN, NaN]); // false
Empty arrays will returns true because there's no duplicate elements:
isUniqueArray([]); // true
A better way if want to check if the array is unique and is not empty:
if (!isEmptyArray(arr) && isUniqueArray(arr)) {
// ...
}
Determines whether the provided array contains only unique values.