Function dedupArrayBy

  • Deduplicate the values in an array using a specified key function. Preserves order.

    Example

    const animals = [
    { id: 1, animal: 'whale' },
    { id: 1, animal: 'gorilla' },
    { id: 2, animal: 'ant' },
    ]
    dedupArrayBy(animals, animal => animal.id) === [
    { id: 1, animal: 'whale' },
    { id: 2, animal: 'ant' },
    ]

    Type Parameters

    • T extends unknown

    Parameters

    • array: T[]

      the array to deduplicate

    • keyFn: ((t) => PropertyKey)

      a function to generate a key to dedup by

        • (t): PropertyKey
        • Parameters

          • t: T

          Returns PropertyKey

    Returns T[]

Generated using TypeDoc