JS Standard LibraryPlaygroundPlayground
GitHubGitHub (opens in a new tab)
  • Introduction
    • arrIns
    • arrReplace
    • arrRm
    • bounds
    • chunk
    • compact
    • countBy
    • diff
    • drop
    • groupBy
    • intersection
    • intersperse
    • max
    • min
    • move
    • range
    • reverse
    • shuffle
    • sort
    • sortBy
    • swap
    • symDiff
    • take
    • union
    • uniq
    • isEmpty
    • isEql
    • isEqlArr
    • isNil
    • isShallowEql
    • aCompose
    • aComposeFn
    • aFilter
    • aForEach
    • aMap
    • aPipe
    • aPipeFn
    • aResolvers
    • hexToRGB
    • rgbToHex
    • compose
    • composeFn
    • noop
    • pipe
    • pipeFn
    • sleep
    • avg
    • clamp
    • divMod
    • isDisjointFrom
    • isEven
    • isOdd
    • isSubsetOf
    • isSupersetOf
    • mean
    • median
    • mode
    • percentage
    • percentageOf
    • prod
    • sum
    • isNegZero
    • isZero
    • toNum
    • clone
    • fromPath
    • get
    • has
    • merge
    • mergeAll
    • omit
    • pick
    • set
    • shallowMerge
    • shallowMergeAll
    • size
    • toPath
    • toSet
    • toUnset
    • unset
    • camelCase
    • capitalize
    • insertAt
    • isEmail
    • pascalCase
    • replaceAt
    • strReplace
    • isArr
    • isArrBuf
    • isAsyFn
    • isBigInt
    • isBlob
    • isBool
    • isDataView
    • isDate
    • isDef
    • isErr
    • isFn
    • isGenFn
    • isInfinity
    • isJSON
    • isMap
    • isNull
    • isNum
    • isObj
    • isPureObj
    • isRegEx
    • isSet
    • isStr
    • isSym
    • isTypedArr
    • isUndef
    • isWkMap
    • isWkRef
    • isWkSet

On This Page

  • Venn Diagram
  • Syntax
  • Examples
  • Try
Question? Give us feedback → (opens in a new tab)
Array
union

Returns unique values in all the given collections.

It uses isEql for deep comparison of values.

Venn Diagram

Difference Venn Diagram

Source: MDN (opens in a new tab)

Related

  • intersection
  • diff
  • symDiff

Syntax

import { union } from '@opentf/std';
 
union(
  collections: unknown[][] = [],
  by?: (val: unknown) => unknown
)

Examples

const evens = [2, 4, 6, 8];
const squares = [1, 4, 9];
union([evens, squares]) //=> [2, 4, 6, 8, 1, 9]
 
const setA = [1, 2, 3];
const setB = [2, 3];
const setC = [2, 3, 4, 5];
union([setA, setB, setC]) //=> [1, 2, 3, 4, 5]

Try

takeuniq

MIT 2024 © Open Tech Foundation.