ixfx
    Preparing search index...

    Function intersection

    Returns the intersection of two arrays: the elements that are in common. Duplicates are removed in the process.

    By default compares based on a string representation of object.

    intersection([1, 2, 3], [2, 4, 6]); // returns [2]
    

    To compare object instances:

    intersection(arrayA, arrayB, (a,b) => a === b)
    

    To use a custom string representation, eg, to only compare based on 'name' property of objects:

    intersection(arrayA, arrayB, (v) => v.name)
    

    See also:

    • uniqueByKey/uniqueByComparer: Get unique items across one or more arrays, including within the array

    Comparer or key-generating function

    • Returns the intersection of two arrays: the elements that are in common. Duplicates are removed in the process.

      Custom function checks equality of objects:

      // Compare based on 'name' property
      intersection(arrayA, arrayB, (a,b) => {
      return a.name === b.name
      })

      Type Parameters

      • V

      Parameters

      Returns V[]

    • Returns the intersection of two arrays: the elements that are in common. Duplicates are removed in the process.

      Custom function makes a string representation of objects to use as the basis for comparison

      intersection(arrayA, arrayB, (v) => v.name)
      

      Type Parameters

      • V

      Parameters

      • arrayA: V[]
      • arrayB: V[]
      • toString: (value: V) => string

      Returns V[]

    • Returns the intersection of two arrays: the elements that are in common. Duplicates are removed in the process.

      Custom function checks equality of objects:

      // Compare based on 'name' property
      intersection(arrayA, arrayB, (a,b) => {
      return a.name === b.name
      })

      Type Parameters

      • V

      Parameters

      • arrayA: V[]
      • arrayB: V[]
      • OptionalcomparerOrKey: IsEqual<V> | ((value: V) => string)

      Returns V[]