unionWith es-toolkit
Creates a new array containing unique elements from two arrays based on a custom equality function.
Usage
unionWith(arr1, arr2, areItemsEqual)
Use unionWith when you want to determine element equality by complex conditions. If the provided function returns true, the two elements are considered the same and duplicates are removed.
You can also use more complex comparison logic.
Here's an example of case-insensitive string comparison.
Parameters
The first array to merge.
The second array to merge.
A function that determines if two elements are equal. It should return true if they are considered equal, and false otherwise.
Returns
Returns the union of the two arrays with duplicates removed based on the custom equality function.
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.