symmetricDifference
Returns the symmetric difference between two arrays: items present in
exactly one of the two arrays (in either, but not both).
null and undefined are treated as empty arrays.
Available since v3.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
array1 | readonly T[] | null | undefined | First array |
array2 | readonly T[] | null | undefined | Second array |
Returns
Section titled “Returns”T[] — Items unique to array1 (in original order), followed by items unique to array2
Examples
Section titled “Examples”Find items unique to either array
Section titled “Find items unique to either array”Complements difference()/intersection() with the “in either, not both” set operation.
Identical arrays have no symmetric difference
Section titled “Identical arrays have no symmetric difference”Items shared by both arrays are excluded entirely.
