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

    Function differenceArray

    • Returns a new array containing elements from the first array that are not present in the second array.

      Type Parameters

      • T

      Parameters

      • a: T[]

        The first array.

      • b: T[]

        The second array.

      Returns T[]

      A new array with elements from a that are not in b.

      This function is useful for finding the difference between two arrays, effectively removing elements from the first array that are also present in the second array. It uses a Set for efficient lookups.

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

      // CommonJS
      const { differenceArray } = require('@bnidev/js-utils')
      // Find elements in array1 that are not in array2
      const array1 = [1, 2, 3, 4, 5]
      const array2 = [3, 4, 5, 6, 7]
      const difference = differenceArray(array1, array2