@bnidev/js-utils
    Preparing search index...

    Function intersectionArray

    • Returns the intersection of two arrays.

      Type Parameters

      • T

      Parameters

      • a: T[]

        The first array.

      • b: T[]

        The second array.

      Returns T[]

      An array containing the elements that are present in both arrays.

      This function is useful for finding common elements between two arrays. It uses a Set for efficient lookups, ensuring that the operation is performed in linear time relative to the size of the input arrays.

      // ES Module
      import { intersectionArray } from '@bnidev/js-utils'

      // CommonJS
      const { intersectionArray } = require('@bnidev/js-utils')
      // Find common elements between two arrays
      const array1 = [1, 2, 3, 4, 5]
      const array2 = [3, 4, 5, 6, 7]
      const intersection = intersectionArray(array1, array2)
      // intersection will be [3, 4, 5]