diginext-utils
Version:
README.md
20 lines • 543 B
JavaScript
/**
* Creates an array of unique values from all given arrays.
*
* @template T - The type of elements in the arrays
* @param arrays - Arrays to combine
* @returns A new array with all unique values from all arrays
*
* @example
* ```ts
* union([1, 2], [2, 3], [3, 4]); // [1, 2, 3, 4]
* union(['a'], ['b'], ['a', 'c']); // ['a', 'b', 'c']
* ```
*/
export function union(...arrays) {
if (!arrays || arrays.length === 0) {
return [];
}
return Array.from(new Set(arrays.flat()));
}
//# sourceMappingURL=union.js.map