tguard-js
    Preparing search index...

    Function isUniqueArray

    • Determines whether the provided array contains only unique values.

      Parameters

      • x: unknown

        The value to validate.

      Returns x is unknown[]

      true if the array contains no duplicate entries, otherwise false.

      This function checks for duplicate entries using JavaScript Set semantics (SameValueZero equality).

      This means:

      • primitive values are compared by value
      • object values are compared by reference identity
      • NaN is considered equal to NaN
      • This function does not perform deep equality comparison.
      • Arrays containing structurally equal but different object references are considered unique.

      Unique 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)) {
      // ...
      }

      1.1