@supuwoerc/toolkit
    Preparing search index...

    Function uniqueBy

    • 根据自定义相等函数对数组进行去重 / Deduplicate array by custom equality function

      Type Parameters

      • T

        数组元素类型 / Array element type

      Parameters

      • array: readonly T[]

        需要去重的数组 / The array to deduplicate

      • equalFn: (a: T, b: T) => boolean

        判断两个元素是否相等的函数 / Function to determine if two elements are equal

      Returns T[]

      去重后的新数组 / New array with duplicates removed

      const arr = [{id: 1}, {id: 2}, {id: 1}]
      const result = uniqueBy(arr, (a, b) => a.id === b.id)
      // result: [{id: 1}, {id: 2}]