intersection es-toolkit
Returns a new array containing elements that are commonly included in both arrays.
Usage
intersection(firstArr, secondArr)
Use intersection when you want to find only common elements in two arrays. It returns a new array containing only elements from the first array that also exist in the second array. This is useful for finding the intersection of two data sets.
It also handles cases with no intersection or special cases.
Parameters
firstArrreadonly T[]required
The first array to compare.
secondArrreadonly T[]required
The second array to compare.
Returns
Returns a new array containing elements commonly included in both arrays.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.