@nevware21/ts-utils
    Preparing search index...

    Function arrUnique

    • Function

      The arrUnique() method returns a new array with duplicate elements removed. Uses the SameValueZero comparison (like strict equality ===, except that NaN is equal to NaN) and maintains insertion order.

      Like arrForEach an empty slot of a sparse array (or a missing index of an array-like) is skipped, so it isn't included as undefined, eg. arrUnique([1, , 3]) is [1, 3].

      Type Parameters

      • T

        Identifies the base type of array elements

      Parameters

      • theArray: ArrayLike<T>

        The array or array-like object to remove duplicates from

      Returns T[]

      A new array with duplicate values removed, preserving order of first occurrence

      0.14.0

      arrUnique([1, 2, 2, 3, 1, 4]);           // [1, 2, 3, 4]
      arrUnique(["a", "b", "a", "c"]); // ["a", "b", "c"]
      arrUnique([1, "1", 1, "1"]); // [1, "1"]
      arrUnique([]); // []
      arrUnique([1]); // [1]

      // Array-like objects
      arrUnique({ length: 4, 0: 1, 1: 2, 2: 2, 3: 3 }); // [1, 2, 3]