Skip to content

intersection

Compute the intersection of two arrays, meaning the elements that are present in both arrays. null and undefined are treated as empty arrays and return [].

Available since v1.0.0

import { intersection } from '@helpers4/array';
intersection<T>(a: readonly T[] | null | undefined, b: readonly T[] | null | undefined): T[]
ParameterTypeDescription
areadonly T[] | null | undefinedFirst array
breadonly T[] | null | undefinedSecond array

T[] — The intersection of the two arrays

Returns elements present in both arrays.

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

View source on GitHub