Identifies the base type of array elements
One or more arrays to combine
A new array containing all unique elements from all arrays
arrUnion([1, 2], [2, 3]); // [1, 2, 3]
arrUnion([1, 2], [3, 4], [4, 5]); // [1, 2, 3, 4, 5]
arrUnion(["a", "b"], ["b", "c"]); // ["a", "b", "c"]
arrUnion([1, 1, 2], [2, 2, 3]); // [1, 2, 3]
arrUnion([], [1, 2]); // [1, 2]
// Array-like objects
arrUnion({ length: 2, 0: 1, 1: 2 }, [2, 3]); // [1, 2, 3]
The arrUnion() method returns a new array containing all unique elements from all provided arrays. Uses the SameValueZero comparison (like strict equality
===, except thatNaNis equal toNaN) and maintains insertion order.Like the other array helpers (eg. arrForEach) a string (or
Stringobject) is read by index, so it is split into its UTF-16 code units (a surrogate pair, eg. an emoji, is two values), unlike arrFrom, which splits it into its code points (as do the iterator helpers, eg. iterUnion, on a runtime withSymbol.iterator).