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

    Function difference

    • Computes the difference between two arrays.

      This function takes two arrays and returns a new array containing the elements that are present in the first array but not in the second array. It effectively filters out any elements from the first array that also appear in the second array.

      计算两个数组之间的差异。

      此函数接收两个数组,并返回一个新数组,其中包含存在于第一个数组中但不在第二个数组中的元素。 它有效地过滤掉第一个数组中同时出现在第二个数组中的任何元素。

      Type Parameters

      • T

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

      Parameters

      • firstArr: readonly T[]

        The first array. 第一个数组

      • secondArr: readonly T[]

        The second array. 第二个数组

      Returns T[]

      A new array containing the elements that are present in the first array but not in the second array. 包含存在于第一个数组中但不在第二个数组中的元素的新数组

      difference([1, 2, 3, 4, 5], [2, 4])
      // => [1, 3, 5]