Function union
- union<T>(...arrays): T[]
Type Parameters
Parameters
Rest...arrays: Iterable<T, any, any>[]The arrays to get the union of.
Returns T[]
A new array containing all distinct elements from the given arrays.
Example: Basic usage
import { union } from "@std/collections/union";
import { assertEquals } from "@std/assert";
const soupIngredients = ["Pepper", "Carrots", "Leek"];
const saladIngredients = ["Carrots", "Radicchio", "Pepper"];
const shoppingList = union(soupIngredients, saladIngredients);
assertEquals(shoppingList, ["Pepper", "Carrots", "Leek", "Radicchio"]);
Returns all distinct elements that appear in any of the given arrays.