@pengzhanbo/utils - v3.7.3
    Preparing search index...

    Function uniqBy

    • Unique array by a custom predicate function

      通过自定义 predicate 函数实现数组去重

      Type Parameters

      • T

        The type of elements in the array / 数组元素的类型

      • U

        The type of the mapped key or second array elements / 映射键或第二个数组元素的类型

      Parameters

      • v: readonly T[]

        The array to remove duplicates from / 要去重的数组

      • predicate: (item: T) => U

        The function to use to transform each element / 用于每个元素的 predicate 函数

      Returns T[]

      The array with duplicates removed / 去重后的数组

      uniqBy([
      { id: 1, name: 'John' },
      { id: 2, name: 'Mark' },
      { id: 3, name: 'John' },
      ], item => item.name)
      // => [{ id: 1, name: 'John' }, { id: 2, name: 'Mark' }]
      uniqBy([1.1, 1.2, 2.1, 2.2], Math.floor)
      // => [1.1, 2.1]